Skip to content

Commit 285d0c0

Browse files
authored
Consistent instrumented span naming (#131)
1 parent f10e4cd commit 285d0c0

File tree

9 files changed

+19
-14
lines changed

9 files changed

+19
-14
lines changed

.changeset/rotten-radios-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@microlabs/otel-cf-workers": minor
3+
---
4+
5+
[Breaking] Rename some instrumented spans for consistency

src/instrumentation/analytics-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function instrumentAEFn(fn: Function, name: string, operation: string) {
3434
kind: SpanKind.CLIENT,
3535
attributes,
3636
}
37-
return tracer.startActiveSpan(`${name} ${operation}`, options, async (span) => {
37+
return tracer.startActiveSpan(`Analytics Engine ${name} ${operation}`, options, async (span) => {
3838
const result = await Reflect.apply(target, thisArg, argArray)
3939
const extraAttrsFn = AEAttributes[operation]
4040
const extraAttrs = extraAttrsFn ? extraAttrsFn(argArray, result) : {}

src/instrumentation/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function instrumentFunction<T extends CacheFns>(fn: T, cacheName: string, op: st
1919
'cache.operation': op,
2020
}
2121
const options: SpanOptions = { kind: SpanKind.CLIENT, attributes }
22-
return tracer.startActiveSpan(`cache:${cacheName}:${op}`, options, async (span) => {
22+
return tracer.startActiveSpan(`Cache ${cacheName} ${op}`, options, async (span) => {
2323
const result = await Reflect.apply(target, thisArg, argArray)
2424
if (op === 'match') {
2525
span.setAttribute('cache.hit', !!result)

src/instrumentation/do-storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function instrumentStorageFn(fn: Function, operation: string) {
176176
operation,
177177
},
178178
}
179-
return tracer.startActiveSpan(`do:storage:${operation}`, options, async (span) => {
179+
return tracer.startActiveSpan(`Durable Object Storage ${operation}`, options, async (span) => {
180180
const result = await Reflect.apply(target, thisArg, argArray)
181181
const extraAttrsFn = StorageAttributes[operation]
182182
const extraAttrs = extraAttrsFn ? extraAttrsFn(argArray, result) : {}

src/instrumentation/do.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function executeDOFetch(fetchFn: FetchFn, request: Request, id: DurableOb
9797
}
9898

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

123123
const name = id.name || ''
124-
const promise = tracer.startActiveSpan(`do.alarmHandler:${name}`, async (span) => {
124+
const promise = tracer.startActiveSpan(`Durable Object Alarm ${name}`, async (span) => {
125125
span.setAttribute(SemanticAttributes.FAAS_COLDSTART, cold_start)
126126
cold_start = false
127127
span.setAttribute('do.id', id.toString())

src/instrumentation/fetch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,20 @@ export function executeFetchHandler(fetchFn: FetchHandler, [request, env, ctx]:
148148
}
149149

150150
const method = request.method.toUpperCase()
151-
const promise = tracer.startActiveSpan(method, options, spanContext, async (span) => {
151+
const promise = tracer.startActiveSpan(`fetchHandler ${method}`, options, spanContext, async (span) => {
152152
const readable = span as unknown as ReadableSpan
153153
try {
154154
const response: Response = await fetchFn(request, env, ctx)
155155
span.setAttributes(gatherResponseAttributes(response))
156156
if (readable.attributes['http.route']) {
157-
span.updateName(`${method} ${readable.attributes['http.route']}`)
157+
span.updateName(`fetchHandler ${method} ${readable.attributes['http.route']}`)
158158
}
159159
span.end()
160160

161161
return response
162162
} catch (error) {
163163
if (readable.attributes['http.route']) {
164-
span.updateName(`${method} ${readable.attributes['http.route']}`)
164+
span.updateName(`fetchHandler ${method} ${readable.attributes['http.route']}`)
165165
}
166166
span.recordException(error as Exception)
167167
span.setStatus({ code: SpanStatusCode.ERROR })
@@ -215,7 +215,7 @@ export function instrumentClientFetch(
215215

216216
const host = new URL(request.url).host
217217
const method = request.method.toUpperCase()
218-
const spanName = typeof attrs?.['name'] === 'string' ? attrs?.['name'] : `${method}: ${host}`
218+
const spanName = typeof attrs?.['name'] === 'string' ? attrs?.['name'] : `fetch ${method} ${host}`
219219
const promise = tracer.startActiveSpan(spanName, options, async (span) => {
220220
const includeTraceContext =
221221
typeof config.includeTraceContext === 'function'

src/instrumentation/kv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function instrumentKVFn(fn: Function, name: string, operation: string) {
8080
kind: SpanKind.CLIENT,
8181
attributes,
8282
}
83-
return tracer.startActiveSpan(`${name} ${operation}`, options, async (span) => {
83+
return tracer.startActiveSpan(`KV ${name} ${operation}`, options, async (span) => {
8484
const result = await Reflect.apply(target, thisArg, argArray)
8585
const extraAttrsFn = KVAttributes[operation]
8686
const extraAttrs = extraAttrsFn ? extraAttrsFn(argArray, result) : {}

src/instrumentation/queue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function executeQueueHandler(queueFn: QueueHandler, [batch, env, ctx]: Qu
143143
kind: SpanKind.CONSUMER,
144144
}
145145
Object.assign(options.attributes!, versionAttributes(env))
146-
const promise = tracer.startActiveSpan(`queueHandler:${batch.queue}`, options, async (span) => {
146+
const promise = tracer.startActiveSpan(`queueHandler ${batch.queue}`, options, async (span) => {
147147
const traceId = span.spanContext().traceId
148148
api_context.active().setValue(traceIdSymbol, traceId)
149149
try {
@@ -191,7 +191,7 @@ function instrumentQueueSend(fn: Queue<unknown>['send'], name: string): Queue<un
191191
const tracer = trace.getTracer('queueSender')
192192
const handler: ProxyHandler<Queue<unknown>['send']> = {
193193
apply: (target, thisArg, argArray) => {
194-
return tracer.startActiveSpan(`queueSend: ${name}`, async (span) => {
194+
return tracer.startActiveSpan(`Queues ${name} send`, async (span) => {
195195
span.setAttribute('queue.operation', 'send')
196196
await Reflect.apply(target, unwrap(thisArg), argArray)
197197
span.end()
@@ -205,7 +205,7 @@ function instrumentQueueSendBatch(fn: Queue<unknown>['sendBatch'], name: string)
205205
const tracer = trace.getTracer('queueSender')
206206
const handler: ProxyHandler<Queue<unknown>['sendBatch']> = {
207207
apply: (target, thisArg, argArray) => {
208-
return tracer.startActiveSpan(`queueSendBatch: ${name}`, async (span) => {
208+
return tracer.startActiveSpan(`Queues ${name} sendBatch`, async (span) => {
209209
span.setAttribute('queue.operation', 'sendBatch')
210210
await Reflect.apply(target, unwrap(thisArg), argArray)
211211
span.end()

src/instrumentation/scheduled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function executeScheduledHandler(
3030
kind: SpanKind.SERVER,
3131
}
3232

33-
const promise = tracer.startActiveSpan('scheduledHandler', options, async (span) => {
33+
const promise = tracer.startActiveSpan(`scheduledHandler ${controller.cron}`, options, async (span) => {
3434
const traceId = span.spanContext().traceId
3535
api_context.active().setValue(traceIdSymbol, traceId)
3636
try {

0 commit comments

Comments
 (0)