Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent instrumented span naming #131

Merged
merged 2 commits into from
Apr 29, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/rotten-radios-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@microlabs/otel-cf-workers": minor
---

[Breaking] Rename some instrumented spans for consistency
2 changes: 1 addition & 1 deletion src/instrumentation/analytics-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function instrumentAEFn(fn: Function, name: string, operation: string) {
kind: SpanKind.CLIENT,
attributes,
}
return tracer.startActiveSpan(`${name} ${operation}`, options, async (span) => {
return tracer.startActiveSpan(`Analytics Engine ${name} ${operation}`, options, async (span) => {
const result = await Reflect.apply(target, thisArg, argArray)
const extraAttrsFn = AEAttributes[operation]
const extraAttrs = extraAttrsFn ? extraAttrsFn(argArray, result) : {}
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function instrumentFunction<T extends CacheFns>(fn: T, cacheName: string, op: st
'cache.operation': op,
}
const options: SpanOptions = { kind: SpanKind.CLIENT, attributes }
return tracer.startActiveSpan(`cache:${cacheName}:${op}`, options, async (span) => {
return tracer.startActiveSpan(`Cache ${cacheName} ${op}`, options, async (span) => {
const result = await Reflect.apply(target, thisArg, argArray)
if (op === 'match') {
span.setAttribute('cache.hit', !!result)
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/do-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function instrumentStorageFn(fn: Function, operation: string) {
operation,
},
}
return tracer.startActiveSpan(`do:storage:${operation}`, options, async (span) => {
return tracer.startActiveSpan(`Durable Object Storage ${operation}`, options, async (span) => {
const result = await Reflect.apply(target, thisArg, argArray)
const extraAttrsFn = StorageAttributes[operation]
const extraAttrs = extraAttrsFn ? extraAttrsFn(argArray, result) : {}
Expand Down
4 changes: 2 additions & 2 deletions src/instrumentation/do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function executeDOFetch(fetchFn: FetchFn, request: Request, id: DurableOb
}

const name = id.name || ''
const promise = tracer.startActiveSpan(`do.fetchHandler:${name}`, options, spanContext, async (span) => {
const promise = tracer.startActiveSpan(`Durable Object Fetch ${name}`, options, spanContext, async (span) => {
try {
const response: Response = await fetchFn(request)
if (response.ok) {
Expand All @@ -121,7 +121,7 @@ export function executeDOAlarm(alarmFn: NonNullable<AlarmFn>, id: DurableObjectI
const tracer = trace.getTracer('DO alarmHandler')

const name = id.name || ''
const promise = tracer.startActiveSpan(`do.alarmHandler:${name}`, async (span) => {
const promise = tracer.startActiveSpan(`Durable Object Alarm ${name}`, async (span) => {
span.setAttribute(SemanticAttributes.FAAS_COLDSTART, cold_start)
cold_start = false
span.setAttribute('do.id', id.toString())
Expand Down
8 changes: 4 additions & 4 deletions src/instrumentation/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,20 @@ export function executeFetchHandler(fetchFn: FetchHandler, [request, env, ctx]:
}

const method = request.method.toUpperCase()
const promise = tracer.startActiveSpan(method, options, spanContext, async (span) => {
const promise = tracer.startActiveSpan(`fetchHandler ${method}`, options, spanContext, async (span) => {
const readable = span as unknown as ReadableSpan
try {
const response: Response = await fetchFn(request, env, ctx)
span.setAttributes(gatherResponseAttributes(response))
if (readable.attributes['http.route']) {
span.updateName(`${method} ${readable.attributes['http.route']}`)
span.updateName(`fetchHandler ${method} ${readable.attributes['http.route']}`)
}
span.end()

return response
} catch (error) {
if (readable.attributes['http.route']) {
span.updateName(`${method} ${readable.attributes['http.route']}`)
span.updateName(`fetchHandler ${method} ${readable.attributes['http.route']}`)
}
span.recordException(error as Exception)
span.setStatus({ code: SpanStatusCode.ERROR })
Expand Down Expand Up @@ -215,7 +215,7 @@ export function instrumentClientFetch(

const host = new URL(request.url).host
const method = request.method.toUpperCase()
const spanName = typeof attrs?.['name'] === 'string' ? attrs?.['name'] : `${method}: ${host}`
const spanName = typeof attrs?.['name'] === 'string' ? attrs?.['name'] : `fetch ${method} ${host}`
const promise = tracer.startActiveSpan(spanName, options, async (span) => {
const includeTraceContext =
typeof config.includeTraceContext === 'function'
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function instrumentKVFn(fn: Function, name: string, operation: string) {
kind: SpanKind.CLIENT,
attributes,
}
return tracer.startActiveSpan(`${name} ${operation}`, options, async (span) => {
return tracer.startActiveSpan(`KV ${name} ${operation}`, options, async (span) => {
const result = await Reflect.apply(target, thisArg, argArray)
const extraAttrsFn = KVAttributes[operation]
const extraAttrs = extraAttrsFn ? extraAttrsFn(argArray, result) : {}
Expand Down
6 changes: 3 additions & 3 deletions src/instrumentation/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function executeQueueHandler(queueFn: QueueHandler, [batch, env, ctx]: Qu
kind: SpanKind.CONSUMER,
}
Object.assign(options.attributes!, versionAttributes(env))
const promise = tracer.startActiveSpan(`queueHandler:${batch.queue}`, options, async (span) => {
const promise = tracer.startActiveSpan(`queueHandler ${batch.queue}`, options, async (span) => {
const traceId = span.spanContext().traceId
api_context.active().setValue(traceIdSymbol, traceId)
try {
Expand Down Expand Up @@ -191,7 +191,7 @@ function instrumentQueueSend(fn: Queue<unknown>['send'], name: string): Queue<un
const tracer = trace.getTracer('queueSender')
const handler: ProxyHandler<Queue<unknown>['send']> = {
apply: (target, thisArg, argArray) => {
return tracer.startActiveSpan(`queueSend: ${name}`, async (span) => {
return tracer.startActiveSpan(`Queues ${name} send`, async (span) => {
span.setAttribute('queue.operation', 'send')
await Reflect.apply(target, unwrap(thisArg), argArray)
span.end()
Expand All @@ -205,7 +205,7 @@ function instrumentQueueSendBatch(fn: Queue<unknown>['sendBatch'], name: string)
const tracer = trace.getTracer('queueSender')
const handler: ProxyHandler<Queue<unknown>['sendBatch']> = {
apply: (target, thisArg, argArray) => {
return tracer.startActiveSpan(`queueSendBatch: ${name}`, async (span) => {
return tracer.startActiveSpan(`Queues ${name} sendBatch`, async (span) => {
span.setAttribute('queue.operation', 'sendBatch')
await Reflect.apply(target, unwrap(thisArg), argArray)
span.end()
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/scheduled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function executeScheduledHandler(
kind: SpanKind.SERVER,
}

const promise = tracer.startActiveSpan('scheduledHandler', options, async (span) => {
const promise = tracer.startActiveSpan(`scheduledHandler ${controller.cron}`, options, async (span) => {
const traceId = span.spanContext().traceId
api_context.active().setValue(traceIdSymbol, traceId)
try {
Expand Down