|
2 | 2 | import { Span, SpanStatusCode, context as TheContextAPI, trace as TheTraceAPI } from '@opentelemetry/api' |
3 | 3 | import { ATTR_EXCEPTION_MESSAGE, ATTR_EXCEPTION_STACKTRACE } from '@opentelemetry/semantic-conventions' |
4 | 4 |
|
5 | | -import { ATTRIBUTES_LEVEL_KEY, ATTRIBUTES_MESSAGE_TEMPLATE_KEY, ATTRIBUTES_SPAN_TYPE_KEY, ATTRIBUTES_TAGS_KEY } from './constants' |
| 5 | +import { |
| 6 | + ATTRIBUTES_LEVEL_KEY, |
| 7 | + ATTRIBUTES_MESSAGE_KEY, |
| 8 | + ATTRIBUTES_MESSAGE_TEMPLATE_KEY, |
| 9 | + ATTRIBUTES_SPAN_TYPE_KEY, |
| 10 | + ATTRIBUTES_TAGS_KEY, |
| 11 | +} from './constants' |
6 | 12 | import { logfireFormatWithExtras } from './formatter' |
7 | 13 | import { logfireApiConfig, ScrubbingOptions, serializeAttributes } from './logfireApiConfig' |
8 | 14 |
|
@@ -62,15 +68,16 @@ export function startSpan( |
62 | 68 | attributes: Record<string, unknown> = {}, |
63 | 69 | { log, tags = [], level = Level.Info, parentSpan }: LogOptions = {} |
64 | 70 | ): Span { |
65 | | - const [formattedMessage, extraAttributes, newTemplate] = logfireFormatWithExtras(msgTemplate, attributes, logfireApiConfig.scrubber) |
| 71 | + const { formattedMessage, extraAttributes, newTemplate } = logfireFormatWithExtras(msgTemplate, attributes, logfireApiConfig.scrubber) |
66 | 72 |
|
67 | 73 | const context = parentSpan ? TheTraceAPI.setSpan(TheContextAPI.active(), parentSpan) : TheContextAPI.active() |
68 | 74 | const span = logfireApiConfig.tracer.startSpan( |
69 | | - formattedMessage, |
| 75 | + msgTemplate, |
70 | 76 | { |
71 | 77 | attributes: { |
72 | 78 | ...serializeAttributes({ ...attributes, ...extraAttributes }), |
73 | 79 | [ATTRIBUTES_MESSAGE_TEMPLATE_KEY]: newTemplate, |
| 80 | + [ATTRIBUTES_MESSAGE_KEY]: formattedMessage, |
74 | 81 | [ATTRIBUTES_LEVEL_KEY]: level, |
75 | 82 | [ATTRIBUTES_TAGS_KEY]: Array.from(new Set(tags).values()), |
76 | 83 | [ATTRIBUTES_SPAN_TYPE_KEY]: log ? 'log' : 'span', |
@@ -118,15 +125,16 @@ export function span<R>(msgTemplate: string, ...args: SpanArgsVariant1<R> | Span |
118 | 125 | callback = args[2] |
119 | 126 | } |
120 | 127 |
|
121 | | - const [formattedMessage, extraAttributes, newTemplate] = logfireFormatWithExtras(msgTemplate, attributes, logfireApiConfig.scrubber) |
| 128 | + const { formattedMessage, extraAttributes, newTemplate } = logfireFormatWithExtras(msgTemplate, attributes, logfireApiConfig.scrubber) |
122 | 129 |
|
123 | 130 | const context = parentSpan ? TheTraceAPI.setSpan(TheContextAPI.active(), parentSpan) : TheContextAPI.active() |
124 | 131 | return logfireApiConfig.tracer.startActiveSpan( |
125 | | - formattedMessage, |
| 132 | + msgTemplate, |
126 | 133 | { |
127 | 134 | attributes: { |
128 | 135 | ...serializeAttributes({ ...attributes, ...extraAttributes }), |
129 | 136 | [ATTRIBUTES_MESSAGE_TEMPLATE_KEY]: newTemplate, |
| 137 | + [ATTRIBUTES_MESSAGE_KEY]: formattedMessage, |
130 | 138 | [ATTRIBUTES_LEVEL_KEY]: level, |
131 | 139 | [ATTRIBUTES_TAGS_KEY]: Array.from(new Set(tags).values()), |
132 | 140 | }, |
|
0 commit comments