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

[Beta] Update Unsupported Messages & Remove Deprecated SemAttrs #1306

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/shim/telemetryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
import { Attributes, context, metrics, ProxyTracerProvider, SpanKind, SpanOptions, SpanStatusCode, diag, trace } from "@opentelemetry/api";
import { logs } from "@opentelemetry/api-logs";
import { LoggerProvider } from "@opentelemetry/sdk-logs";
import { SemanticAttributes } from "@opentelemetry/semantic-conventions";
import {
SEMATTRS_DB_STATEMENT,
SEMATTRS_DB_SYSTEM,
SEMATTRS_HTTP_METHOD,
SEMATTRS_HTTP_STATUS_CODE,
SEMATTRS_HTTP_URL,
SEMATTRS_PEER_SERVICE,
SEMATTRS_RPC_GRPC_STATUS_CODE,
SEMATTRS_RPC_METHOD,
SEMATTRS_RPC_SYSTEM
} from "@opentelemetry/semantic-conventions";
import * as Contracts from "../declarations/contracts";
import { TelemetryItem as Envelope } from "../declarations/generated";
import { Context } from "./context";
Expand Down Expand Up @@ -163,9 +173,9 @@ export class TelemetryClient {
const attributes: Attributes = {
...telemetry.properties,
};
attributes[SemanticAttributes.HTTP_METHOD] = "HTTP";
attributes[SemanticAttributes.HTTP_URL] = telemetry.url;
attributes[SemanticAttributes.HTTP_STATUS_CODE] = telemetry.resultCode;
attributes[SEMATTRS_HTTP_METHOD] = "HTTP";
attributes[SEMATTRS_HTTP_URL] = telemetry.url;
attributes[SEMATTRS_HTTP_STATUS_CODE] = telemetry.resultCode;
const options: SpanOptions = {
kind: SpanKind.SERVER,
attributes: attributes,
Expand Down Expand Up @@ -210,20 +220,20 @@ export class TelemetryClient {
};
if (telemetry.dependencyTypeName) {
if (telemetry.dependencyTypeName.toLowerCase().indexOf("http") > -1) {
attributes[SemanticAttributes.HTTP_METHOD] = "HTTP";
attributes[SemanticAttributes.HTTP_URL] = telemetry.data;
attributes[SemanticAttributes.HTTP_STATUS_CODE] = telemetry.resultCode;
attributes[SEMATTRS_HTTP_METHOD] = "HTTP";
attributes[SEMATTRS_HTTP_URL] = telemetry.data;
attributes[SEMATTRS_HTTP_STATUS_CODE] = telemetry.resultCode;
} else if (Util.getInstance().isDbDependency(telemetry.dependencyTypeName)) {
attributes[SemanticAttributes.DB_SYSTEM] = telemetry.dependencyTypeName;
attributes[SemanticAttributes.DB_STATEMENT] = telemetry.data;
attributes[SEMATTRS_DB_SYSTEM] = telemetry.dependencyTypeName;
attributes[SEMATTRS_DB_STATEMENT] = telemetry.data;
} else if (telemetry.dependencyTypeName.toLowerCase().indexOf("rpc") > -1) {
attributes[SemanticAttributes.RPC_SYSTEM] = telemetry.dependencyTypeName;
attributes[SemanticAttributes.RPC_METHOD] = telemetry.name;
attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE] = telemetry.resultCode;
attributes[SEMATTRS_RPC_SYSTEM] = telemetry.dependencyTypeName;
attributes[SEMATTRS_RPC_METHOD] = telemetry.data;
attributes[SEMATTRS_RPC_GRPC_STATUS_CODE] = telemetry.resultCode;
}
}
if (telemetry.target) {
attributes[SemanticAttributes.PEER_SERVICE] = telemetry.target;
attributes[SEMATTRS_PEER_SERVICE] = telemetry.target;
}
const options: SpanOptions = {
kind: SpanKind.CLIENT,
Expand Down
4 changes: 2 additions & 2 deletions test/unitTests/shim/telemetryClient.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AzureMonitorExporterOptions, AzureMonitorMetricExporter } from "@azure/
import { MeterProvider, PeriodicExportingMetricReader, PeriodicExportingMetricReaderOptions, ResourceMetrics } from "@opentelemetry/sdk-metrics";
import { LogRecord, LogRecordProcessor, LoggerProvider } from "@opentelemetry/sdk-logs";
import { logs } from "@opentelemetry/api-logs";
import { SemanticAttributes } from "@opentelemetry/semantic-conventions";
import { SEMATTRS_RPC_SYSTEM } from "@opentelemetry/semantic-conventions";

describe("shim/TelemetryClient", () => {
let client: TelemetryClient;
Expand Down Expand Up @@ -169,7 +169,7 @@ describe("shim/TelemetryClient", () => {
const spans = testProcessor.spansProcessed;
assert.equal(spans.length, 1);
assert.equal(spans[0].name, "TestName");
assert.equal(spans[0].attributes[SemanticAttributes.RPC_SYSTEM], "RPC");
assert.equal(spans[0].attributes[SEMATTRS_RPC_SYSTEM], "RPC");
});

it("trackRequest", async () => {
Expand Down