From c344023798b201e34311eba1febbd8f1fcc67673 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:26:10 -0800 Subject: [PATCH] [monitor-opentelemetry-exporter] Truncate operation name context tag (#31283) ### Packages impacted by this PR @azure/monitor-opentelemetry-exporter ### Issues associated with this PR https://github.com/microsoft/ApplicationInsights-node.js/issues/1383#issuecomment-2386384129 --- .../src/utils/spanUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sdk/monitor/monitor-opentelemetry-exporter/src/utils/spanUtils.ts b/sdk/monitor/monitor-opentelemetry-exporter/src/utils/spanUtils.ts index 583cf0c355c1..0bd336414672 100644 --- a/sdk/monitor/monitor-opentelemetry-exporter/src/utils/spanUtils.ts +++ b/sdk/monitor/monitor-opentelemetry-exporter/src/utils/spanUtils.ts @@ -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 */ }