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

feat: mark run activity span as consumer span #1500

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
14 changes: 12 additions & 2 deletions packages/interceptors-opentelemetry/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function wrapWithSpan<T>(
export interface InstrumentOptions<T> {
tracer: otel.Tracer;
spanName: string;
spanOptions?: otel.SpanOptions;
fn: (span: otel.Span) => Promise<T>;
context?: otel.Context;
acceptableErrors?: (err: unknown) => boolean;
Expand All @@ -69,14 +70,23 @@ export interface InstrumentOptions<T> {
export async function instrument<T>({
tracer,
spanName,
spanOptions = {},
fn,
context,
acceptableErrors,
}: InstrumentOptions<T>): Promise<T> {
if (context) {
return await otel.context.with(context, async () => {
return await tracer.startActiveSpan(spanName, async (span) => await wrapWithSpan(span, fn, acceptableErrors));
return await tracer.startActiveSpan(
spanName,
spanOptions,
async (span) => await wrapWithSpan(span, fn, acceptableErrors)
);
});
}
return await tracer.startActiveSpan(spanName, async (span) => await wrapWithSpan(span, fn, acceptableErrors));
return await tracer.startActiveSpan(
spanName,
spanOptions,
async (span) => await wrapWithSpan(span, fn, acceptableErrors)
);
}
8 changes: 7 additions & 1 deletion packages/interceptors-opentelemetry/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ export class OpenTelemetryActivityInboundInterceptor implements ActivityInboundC
async execute(input: ActivityExecuteInput, next: Next<ActivityInboundCallsInterceptor, 'execute'>): Promise<unknown> {
const context = await extractContextFromHeaders(input.headers);
const spanName = `${SpanName.ACTIVITY_EXECUTE}${SPAN_DELIMITER}${this.ctx.info.activityType}`;
return await instrument({ tracer: this.tracer, spanName, fn: () => next(input), context });
return await instrument({
tracer: this.tracer,
spanName,
spanOptions: { attributes: { 'messaging.system': 'temporal' }, kind: otel.SpanKind.CONSUMER },
fn: () => next(input),
context,
});
}
}

Expand Down
Loading