-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[OpenTelemetry Exporter] Update AI mapping with latest spec changes #17916
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// Licensed under the MIT license. | ||
|
||
import os from "os"; | ||
import { URL } from "url"; | ||
import { ReadableSpan } from "@opentelemetry/tracing"; | ||
import { hrTimeToMilliseconds } from "@opentelemetry/core"; | ||
import { diag, SpanKind, SpanStatusCode, Link } from "@opentelemetry/api"; | ||
|
@@ -56,10 +57,22 @@ function createTagsFromSpan(span: ReadableSpan): Tags { | |
} | ||
if (span.kind === SpanKind.SERVER) { | ||
const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD]; | ||
let httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP]; | ||
let netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP]; | ||
const httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP]; | ||
const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP]; | ||
if (httpMethod) { | ||
tags[KnownContextTagKeys.AiOperationName] = `${httpMethod as string} ${span.name as string}`; | ||
const httpRoute = span.attributes[SemanticAttributes.HTTP_ROUTE]; | ||
const httpUrl = span.attributes[SemanticAttributes.HTTP_URL]; | ||
tags[KnownContextTagKeys.AiOperationName] = span.name; // Default | ||
if (httpRoute) { | ||
tags[KnownContextTagKeys.AiOperationName] = `${httpMethod as string} ${httpRoute as string}`; | ||
} | ||
else if (httpUrl) { | ||
try { | ||
let url = new URL(String(httpUrl)); | ||
tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`; | ||
} | ||
catch (ex) { } | ||
} | ||
if (httpClientIp) { | ||
tags[KnownContextTagKeys.AiLocationIp] = String(httpClientIp); | ||
} else if (netPeerIp) { | ||
|
@@ -182,7 +195,7 @@ function getDependencyTarget(span: ReadableSpan): string { | |
|
||
function createDependencyData(span: ReadableSpan): RemoteDependencyData { | ||
const remoteDependencyData: RemoteDependencyData = { | ||
name: span.name, | ||
name: span.name, //Default | ||
id: `${span.spanContext().spanId}`, | ||
success: span.status.code != SpanStatusCode.ERROR, | ||
resultCode: "0", | ||
|
@@ -202,6 +215,14 @@ function createDependencyData(span: ReadableSpan): RemoteDependencyData { | |
const rpcSystem = span.attributes[SemanticAttributes.RPC_SYSTEM]; | ||
// HTTP Dependency | ||
if (httpMethod) { | ||
const httpUrl = span.attributes[SemanticAttributes.HTTP_URL]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, accessing dictionary attributes won't through an exception if it doesn't exist in JS? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will only throw if span.attributes doesn't exist, in this case if HTTP_URL is not there will return undefined |
||
if (httpUrl) { | ||
try { | ||
let dependencyUrl = new URL(String(httpUrl)); | ||
remoteDependencyData.name = `${httpMethod} ${dependencyUrl.pathname}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment about default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is added by URL object, there must be a test in this PR where this is validated |
||
} | ||
catch (ex) { } | ||
} | ||
remoteDependencyData.type = DependencyTypes.Http; | ||
remoteDependencyData.data = getUrl(span); | ||
const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE]; | ||
|
@@ -222,7 +243,7 @@ function createDependencyData(span: ReadableSpan): RemoteDependencyData { | |
target = res[1] + res[2] + res[4]; | ||
} | ||
} | ||
} catch (error) {} | ||
} catch (error) { } | ||
remoteDependencyData.target = `${target}`; | ||
} | ||
} | ||
|
@@ -243,13 +264,17 @@ function createDependencyData(span: ReadableSpan): RemoteDependencyData { | |
remoteDependencyData.type = String(dbSystem); | ||
} | ||
const dbStatement = span.attributes[SemanticAttributes.DB_STATEMENT]; | ||
const dbOperation = span.attributes[SemanticAttributes.DB_OPERATION]; | ||
if (dbStatement) { | ||
remoteDependencyData.data = String(dbStatement); | ||
} | ||
else if (dbOperation) { | ||
remoteDependencyData.data = String(dbOperation); | ||
} | ||
let target = getDependencyTarget(span); | ||
const dbName = span.attributes[SemanticAttributes.DB_NAME]; | ||
if (target) { | ||
remoteDependencyData.target = dbName ? `${target}/${dbName}` : `${target}`; | ||
remoteDependencyData.target = dbName ? `${target}|${dbName}` : `${target}`; | ||
} else { | ||
remoteDependencyData.target = dbName ? `${dbName}` : `${dbSystem}`; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the path name change to
/
if empty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes