Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [7.5.0] - 2026-07-28
### Added
- Add a generic `IUserLandTracer.setFallbackSpanTag` API and exported GraphQL operation tag constants.

## [7.4.0] - 2026-06-22
### Changed
- Renamed the base `IOClients` Janus Catalog getter from `catalogSystem` to
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vtex/api",
"version": "7.4.0",
"version": "7.5.0",
"description": "VTEX I/O API client",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ export class TestTracer implements IUserLandTracer {
public fallbackSpanContext() {
return this.fallbackSpan.context()
}

public setFallbackSpanTag(key: string, value: unknown): void {
this.fallbackSpan.setTag(key, value)
}
}
5 changes: 5 additions & 0 deletions src/tracing/Tags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tags as OpentracingTags } from 'opentracing'
export { OpentracingTags }

Check notice on line 2 in src/tracing/Tags.ts

View check run for this annotation

Sonar - Workflows / SonarQube Code Analysis

src/tracing/Tags.ts#L2

Use `export…from` to re-export `OpentracingTags`.

/* tslint:disable:object-literal-sort-keys */

Expand Down Expand Up @@ -74,6 +74,11 @@
HTTP_RETRY_COUNT = 'http.retry.count',
}

export const enum GraphQLTags {
GRAPHQL_OPERATION_NAME = 'graphql.operation.name',
GRAPHQL_OPERATION_TYPE = 'graphql.operation.type',
}

export const UserlandTags = {
...OpentracingTags,
}
63 changes: 63 additions & 0 deletions src/tracing/UserLandTracer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { MockSpan, MockTracer } from '@tiagonapoli/opentracing-alternate-mock'

import { GraphQLTags } from './Tags'
import { UserLandTracer } from './UserLandTracer'

describe('UserLandTracer.setFallbackSpanTag', () => {
test('writes a tag only to the fallback span', () => {
const tracer = new MockTracer()
const fallback = tracer.startSpan('incoming-request') as MockSpan
const userLandTracer = new UserLandTracer(tracer, fallback)

userLandTracer.setFallbackSpanTag(
GraphQLTags.GRAPHQL_OPERATION_NAME,
'GetProduct'
)
const child = userLandTracer.startSpan('child') as MockSpan

expect(fallback.tags()).toHaveProperty(
[GraphQLTags.GRAPHQL_OPERATION_NAME],
'GetProduct'
)
expect(child.tags()).not.toHaveProperty(
[GraphQLTags.GRAPHQL_OPERATION_NAME]
)
})

test('is a no-op when there is no fallback span', () => {
const userLandTracer = new UserLandTracer(new MockTracer())

expect(() => {
userLandTracer.setFallbackSpanTag(
GraphQLTags.GRAPHQL_OPERATION_TYPE,
'query'
)
}).not.toThrow()
})

test('can write after the fallback span is locked', () => {
const tracer = new MockTracer()
const fallback = tracer.startSpan('incoming-request') as MockSpan
const replacement = tracer.startSpan('replacement') as MockSpan
const userLandTracer = new UserLandTracer(tracer, fallback)

userLandTracer.lockFallbackSpan()

expect(() => userLandTracer.setFallbackSpan(replacement)).toThrow(
"FallbackSpan is locked, can't change it"
)
expect(() => {
userLandTracer.setFallbackSpanTag(
GraphQLTags.GRAPHQL_OPERATION_TYPE,
'query'
)
}).not.toThrow()
expect(fallback.tags()).toHaveProperty(
[GraphQLTags.GRAPHQL_OPERATION_TYPE],
'query'
)
expect(replacement.tags()).not.toHaveProperty(
[GraphQLTags.GRAPHQL_OPERATION_TYPE]
)
})
})
5 changes: 5 additions & 0 deletions src/tracing/UserLandTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
startSpan: Tracer['startSpan']
inject: Tracer['inject']
fallbackSpanContext: () => SpanContext | undefined
setFallbackSpanTag: (key: string, value: unknown) => void
}

export const createTracingContextFromCarrier = (
Expand All @@ -27,14 +28,14 @@
}

export class UserLandTracer implements IUserLandTracer {
private tracer: Tracer

Check warning on line 31 in src/tracing/UserLandTracer.ts

View check run for this annotation

Sonar - Workflows / SonarQube Code Analysis

src/tracing/UserLandTracer.ts#L31

Member 'tracer' is never reassigned; mark it as `readonly`.
private fallbackSpan: Span | undefined
private fallbackSpanLock: boolean

// tslint:disable-next-line
private _isSampled: boolean

Check warning on line 36 in src/tracing/UserLandTracer.ts

View check run for this annotation

Sonar - Workflows / SonarQube Code Analysis

src/tracing/UserLandTracer.ts#L36

Member '_isSampled' is never reassigned; mark it as `readonly`.
// tslint:disable-next-line
private _traceId?: string

Check warning on line 38 in src/tracing/UserLandTracer.ts

View check run for this annotation

Sonar - Workflows / SonarQube Code Analysis

src/tracing/UserLandTracer.ts#L38

Member '_traceId' is never reassigned; mark it as `readonly`.

constructor(tracer: Tracer, fallbackSpan?: Span) {
this.tracer = tracer
Expand Down Expand Up @@ -81,4 +82,8 @@
public fallbackSpanContext(): SpanContext | undefined {
return this.fallbackSpan?.context()
}

public setFallbackSpanTag(key: string, value: unknown): void {
this.fallbackSpan?.setTag(key, value)
}
}
2 changes: 1 addition & 1 deletion src/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export { ErrorReport } from './errorReporting/ErrorReport'
export { createSpanReference } from './spanReference/createSpanReference'
export { SpanReferenceTypes } from './spanReference/SpanReferenceTypes'
export { UserlandTags as TracingTags } from './Tags'
export { UserlandTags as TracingTags, GraphQLTags } from './Tags'
export { createTracingContextFromCarrier, IUserLandTracer } from './UserLandTracer'
export { getTraceInfo, TraceInfo } from './utils'
export { Span, FORMAT_HTTP_HEADERS }

Check notice on line 10 in src/tracing/index.ts

View check run for this annotation

Sonar - Workflows / SonarQube Code Analysis

src/tracing/index.ts#L10

Use `export…from` to re-export `Span`.

Check notice on line 10 in src/tracing/index.ts

View check run for this annotation

Sonar - Workflows / SonarQube Code Analysis

src/tracing/index.ts#L10

Use `export…from` to re-export `FORMAT_HTTP_HEADERS`.
Loading