Skip to content
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
16 changes: 12 additions & 4 deletions packages/opentelemetry-node/src/spanprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
const sentryChildSpan = sentryParentSpan.startChild({
description: otelSpan.name,
// instrumentor: 'otel',
startTimestamp: otelSpan.startTime[0],
startTimestamp: convertOtelTimeToSeconds(otelSpan.startTime),
spanId: otelSpanId,
});

Expand All @@ -56,7 +56,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
name: otelSpan.name,
...traceCtx,
// instrumentor: 'otel',
startTimestamp: otelSpan.startTime[0],
startTimestamp: convertOtelTimeToSeconds(otelSpan.startTime),
spanId: otelSpanId,
});

Expand All @@ -82,7 +82,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
finishTransactionWithContextFromOtelData(sentrySpan, otelSpan);
} else {
updateSpanWithOtelData(sentrySpan, otelSpan);
sentrySpan.finish(otelSpan.endTime[0]);
sentrySpan.finish(convertOtelTimeToSeconds(otelSpan.endTime));
}

this._map.delete(otelSpanId);
Expand Down Expand Up @@ -123,7 +123,7 @@ function finishTransactionWithContextFromOtelData(transaction: Transaction, otel
resource: otelSpan.resource.attributes,
});

transaction.finish(otelSpan.endTime[0]);
transaction.finish(convertOtelTimeToSeconds(otelSpan.endTime));
});
}

Expand All @@ -145,4 +145,12 @@ function updateSpanWithOtelData(sentrySpan: SentrySpan, otelSpan: OtelSpan): voi

function updateTransactionWithOtelData(transaction: Transaction, otelSpan: OtelSpan): void {
transaction.setStatus(mapOtelStatus(otelSpan));

const { op, description } = parseSpanDescription(otelSpan);
transaction.op = op;
transaction.name = description;
}

function convertOtelTimeToSeconds([seconds, nano]: [number, number]): number {
return seconds + nano / 1_000_000_000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function descriptionForDbSystem(otelSpan: OtelSpan, _dbSystem: AttributeValue):
}

function descriptionForHttpMethod(otelSpan: OtelSpan, httpMethod: AttributeValue): SpanDescription {
const { name, kind } = otelSpan;
const { name, kind, attributes } = otelSpan;

const opParts = ['http'];

Expand All @@ -82,8 +82,15 @@ function descriptionForHttpMethod(otelSpan: OtelSpan, httpMethod: AttributeValue
break;
}

// Ex. description="GET /api/users/{user_id}".
const description = `${httpMethod} ${name}`;
// Ex. /api/users
const httpPath = attributes[SemanticAttributes.HTTP_ROUTE] || attributes[SemanticAttributes.HTTP_TARGET];

if (!httpPath) {
return { op: opParts.join('.'), description: name };
}

// Ex. description="GET /api/users".
const description = `${httpMethod} ${httpPath}`;

return { op: opParts.join('.'), description };
}
Loading