-
Notifications
You must be signed in to change notification settings - Fork 821
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
SpanProcess.onStart does not have access to span attributes #4188
Comments
So I checked the issue and want to be a contributor to this. I checked both your options on either calling the spanprocessor or modifying the constructor:
const span = new Span(
this,
context,
name,
spanContext,
spanKind,
parentSpanId,
links,
options.startTime
);
// Set initial span attributes. The attributes object may have been mutated
// by the sampler, so we sanitize the merged attributes before setting them.
const initAttributes = sanitizeAttributes(
Object.assign(attributes, samplingResult.attributes)
);
span.setAttributes(initAttributes);
span.registerProcessor(): Seems really clunky tho...
constructor(
parentTracer: Tracer,
context: Context,
spanName: string,
spanContext: SpanContext,
kind: SpanKind,
parentSpanId?: string,
links: Link[] = [],
startTime?: TimeInput,
_deprecatedClock?: unknown, // keeping this argument even though it is unused to ensure backwards compatibility,
initAttributes?: Attributes
) {
this.name = spanName;
this._spanContext = spanContext;
this.parentSpanId = parentSpanId;
this.kind = kind;
this.links = links;
if(initAttributes){
this.setAttributes(initAttributes);
}
const now = Date.now();
this._performanceStartTime = otperformance.now();
this._performanceOffset =
now - (this._performanceStartTime + getTimeOrigin());
this._startTimeProvided = startTime != null;
this.startTime = this._getTime(startTime ?? now);
this.resource = parentTracer.resource;
this.instrumentationLibrary = parentTracer.instrumentationLibrary;
this._spanLimits = parentTracer.getSpanLimits();
this._spanProcessor = parentTracer.getActiveSpanProcessor();
this._spanProcessor.onStart(this, context);
this._attributeValueLengthLimit =
this._spanLimits.attributeValueLengthLimit || 0;
} Doesn't seem like the span has optional variables like this till now atleast, but I think it would be simple enough, would not break in the constructor or the wrapped call in the constructor. Let me know what you think and I can make a PR about it. |
Thanks for the clarification @ArtAhmetaj - indeed, I was thinking the constructor isn't called but you are right that it may be since it is currently a public API. Actually coincidentally, I found it used in such a way in Prisma instrumentation just yesterday. So the second approach seems better to me too |
What happened?
Steps to Reproduce
Access
span.attributes
in aSpanProcessor.onStart
methodExpected Result
Read attributes
Actual Result
Attributes always empty
Additional Details
Span processor is called in span constructor
opentelemetry-js/packages/opentelemetry-sdk-trace-base/src/Span.ts
Line 123 in 5ce32c0
But attributes are set after
https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-sdk-trace-base/src/Tracer.ts#L150
Presumably it would be better to call the spanprocessor from
Tracer.startSpan
instead of constructor. Alternatively, attributes could be passed into the constructor though backwards compatibility may be challenging.OpenTelemetry Setup Code
No response
package.json
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: