Skip to content

Commit

Permalink
[monitor-opentelemetry-exporter] Truncate operation name context tag (#…
Browse files Browse the repository at this point in the history
…31283)

### Packages impacted by this PR
@azure/monitor-opentelemetry-exporter

### Issues associated with this PR

microsoft/ApplicationInsights-node.js#1383 (comment)
  • Loading branch information
hectorhdzg authored Dec 6, 2024
1 parent 00482d3 commit c344023
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ function createTagsFromSpan(span: ReadableSpan): Tags {
const httpUrl = span.attributes[SEMATTRS_HTTP_URL];
tags[KnownContextTagKeys.AiOperationName] = span.name; // Default
if (httpRoute) {
tags[KnownContextTagKeys.AiOperationName] = `${httpMethod as string} ${
httpRoute as string
}`;
// AiOperationName max lenght is 1024
// https://github.com/MohanGsk/ApplicationInsights-Home/blob/master/EndpointSpecs/Schemas/Bond/ContextTagKeys.bond
tags[KnownContextTagKeys.AiOperationName] = String(
`${httpMethod as string} ${httpRoute as string}`,
).substring(0, MaxPropertyLengths.TEN_BIT);
} else if (httpUrl) {
try {
const url = new URL(String(httpUrl));
tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`;
tags[KnownContextTagKeys.AiOperationName] = String(
`${httpMethod} ${url.pathname}`,
).substring(0, MaxPropertyLengths.TEN_BIT);
} catch {
/* no-op */
}
Expand Down

0 comments on commit c344023

Please sign in to comment.