diff --git a/src/shim/shim-config.ts b/src/shim/shim-config.ts index b7a057af..cc971ed2 100644 --- a/src/shim/shim-config.ts +++ b/src/shim/shim-config.ts @@ -5,7 +5,7 @@ import https = require("https"); import azureCoreAuth = require("@azure/core-auth"); import { diag } from "@opentelemetry/api"; import { HttpInstrumentationConfig } from "@opentelemetry/instrumentation-http"; -import { DistributedTracingModes, IConfig, IDisabledExtendedMetrics, IWebInstrumentationConfig } from "./types"; +import { DistributedTracingModes, IConfig, IDisabledExtendedMetrics, IWebInstrumentationConfig, UNSUPPORTED_MSG } from "./types"; import { ShimJsonConfig } from "./shim-jsonConfig"; import { AzureMonitorOpenTelemetryOptions, InstrumentationOptions, InstrumentationOptionsType } from "../types"; @@ -302,54 +302,54 @@ class Config implements IConfig { process.env[ENV_nativeMetricsDisablers] || this.extendedMetricDisablers ) { - this._configWarnings.push("Extended metrics are no longer supported."); + this._configWarnings.push(`Extended metrics are no longer supported. ${UNSUPPORTED_MSG}`); } if (this.disableAppInsights) { - this._configWarnings.push("disableAppInsights configuration no longer supported."); + this._configWarnings.push(`disableAppInsights configuration no longer supported. ${UNSUPPORTED_MSG}`); } if (this.enableAutoCollectHeartbeat === true) { - this._configWarnings.push("Heartbeat metrics are no longer supported."); + this._configWarnings.push(`Heartbeat metrics are no longer supported. ${UNSUPPORTED_MSG}`); } if (this.enableAutoDependencyCorrelation === false) { - this._configWarnings.push("Auto dependency correlation cannot be turned off anymore."); + this._configWarnings.push(`Auto dependency correlation cannot be turned off anymore. ${UNSUPPORTED_MSG}`); } if (typeof (this.enableAutoCollectIncomingRequestAzureFunctions) === "boolean") { - this._configWarnings.push("Auto request generation in Azure Functions is no longer supported."); + this._configWarnings.push(`Auto request generation in Azure Functions is no longer supported. ${UNSUPPORTED_MSG}`); } if (this.enableUseAsyncHooks === false) { - this._configWarnings.push("The use of non async hooks is no longer supported."); + this._configWarnings.push(`The use of non async hooks is no longer supported. ${UNSUPPORTED_MSG}`); } if (this.distributedTracingMode === DistributedTracingModes.AI) { - this._configWarnings.push("AI only distributed tracing mode is no longer supported."); + this._configWarnings.push(`AI only distributed tracing mode is no longer supported. ${UNSUPPORTED_MSG}`); } if (this.enableResendInterval) { - this._configWarnings.push("The resendInterval configuration option is not supported by the shim."); + this._configWarnings.push(`The resendInterval configuration option is not supported by the shim. ${UNSUPPORTED_MSG}`); } if (this.enableMaxBytesOnDisk) { - this._configWarnings.push("The maxBytesOnDisk configuration option is not supported by the shim."); + this._configWarnings.push(`The maxBytesOnDisk configuration option is not supported by the shim. ${UNSUPPORTED_MSG}`); } if (this.ignoreLegacyHeaders === false) { - this._configWarnings.push("LegacyHeaders are not supported by the shim."); + this._configWarnings.push(`LegacyHeaders are not supported by the shim. ${UNSUPPORTED_MSG}`); } if (this.maxBatchSize) { - this._configWarnings.push("The maxBatchSize configuration option is not supported by the shim."); + this._configWarnings.push(`The maxBatchSize configuration option is not supported by the shim. ${UNSUPPORTED_MSG}`); } if (this.enableLoggerErrorToTrace) { - this._configWarnings.push("The enableLoggerErrorToTrace configuration option is not supported by the shim."); + this._configWarnings.push(`The enableLoggerErrorToTrace configuration option is not supported by the shim. ${UNSUPPORTED_MSG}`); } if (this.httpAgent || this.httpsAgent) { - this._configWarnings.push("The httpAgent and httpsAgent configuration options are not supported by the shim."); + this._configWarnings.push(`The httpAgent and httpsAgent configuration options are not supported by the shim. ${UNSUPPORTED_MSG}`); } if ( this.webInstrumentationConfig || this.webInstrumentationSrc ) { - this._configWarnings.push("The webInstrumentation config and src options are not supported by the shim."); + this._configWarnings.push(`The webInstrumentation config and src options are not supported by the shim. ${UNSUPPORTED_MSG}`); } if (this.quickPulseHost) { - this._configWarnings.push("The quickPulseHost configuration option is not supported by the shim."); + this._configWarnings.push(`The quickPulseHost configuration option is not supported by the shim. ${UNSUPPORTED_MSG}`); } if (this.correlationHeaderExcludedDomains) { - this._configWarnings.push("The correlationHeaderExcludedDomains configuration option is not supported by the shim."); + this._configWarnings.push(`The correlationHeaderExcludedDomains configuration option is not supported by the shim. ${UNSUPPORTED_MSG}`); } if ( process.env[ENV_iKey] || @@ -357,13 +357,13 @@ class Config implements IConfig { process.env[ENV_azurePrefix + ENV_iKey] || process.env[ENV_azurePrefix + legacy_ENV_iKey] ) { - this._configWarnings.push("The iKey configuration option is not supported by the shim. Please configure the the connection string instead."); + this._configWarnings.push(`The iKey configuration option is not supported by the shim. Please configure the the connection string instead. ${UNSUPPORTED_MSG}`); } if (process.env[ENV_profileQueryEndpoint]) { - this._configWarnings.push("The profileQueryEndpoint configuration option is not supported by the shim."); + this._configWarnings.push(`The profileQueryEndpoint configuration option is not supported by the shim. ${UNSUPPORTED_MSG}`); } if (process.env[ENV_quickPulseHost]) { - this._configWarnings.push("Please configure the quickPulseHost in the connection string instead."); + this._configWarnings.push(`Please configure the quickPulseHost in the connection string instead. ${UNSUPPORTED_MSG}`); } return options; } diff --git a/src/shim/telemetryClient.ts b/src/shim/telemetryClient.ts index a33a465b..08a0f794 100644 --- a/src/shim/telemetryClient.ts +++ b/src/shim/telemetryClient.ts @@ -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"; @@ -16,6 +26,7 @@ import { AttributeLogProcessor } from "../shared/util/attributeLogRecordProcesso import { LogApi } from "./logsApi"; import { flushAzureMonitor, shutdownAzureMonitor, useAzureMonitor } from "../main"; import { AzureMonitorOpenTelemetryOptions } from "../types"; +import { UNSUPPORTED_MSG } from "./types"; /** * Application Insights telemetry client provides interface to track telemetry items, register telemetry initializers and @@ -163,9 +174,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, @@ -210,20 +221,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, @@ -243,7 +254,7 @@ export class TelemetryClient { * @param telemetryType specify the type of telemetry you are tracking from the list of Contracts.DataTypes */ public track(telemetry: Contracts.Telemetry, telemetryType: Contracts.TelemetryType) { - throw new Error("Not implemented"); + throw new Error(`Not implemented. Please use the specific track method for the type of telemetry you are tracking. ${UNSUPPORTED_MSG}`); } /** @@ -259,7 +270,7 @@ export class TelemetryClient { * Get Authorization handler */ public getAuthorizationHandler(config: Config): void { - diag.warn("getAuthorizationHandler is not supported in ApplicationInsights any longer."); + diag.warn(`getAuthorizationHandler is not supported in ApplicationInsights any longer. ${UNSUPPORTED_MSG}`); } /* @@ -289,7 +300,7 @@ export class TelemetryClient { contextObjects?: { [name: string]: any } ) => boolean ) { - diag.warn("addTelemetryProcessor is not supported in ApplicationInsights any longer."); + diag.warn(`addTelemetryProcessor is not supported in ApplicationInsights any longer. ${UNSUPPORTED_MSG}`); } /* diff --git a/src/shim/types.ts b/src/shim/types.ts index 73ee85cf..91cc73f1 100644 --- a/src/shim/types.ts +++ b/src/shim/types.ts @@ -5,6 +5,7 @@ import { TokenCredential } from "@azure/core-auth"; import * as http from "http"; import https = require("https"); +export const UNSUPPORTED_MSG = "Please reference the Azure Monitor OpenTelemetry Migration Doc for more information. If this functionality is required, please revert to Application Insights 2.X SDK."; export enum DistributedTracingModes { /** * Send Application Insights correlation headers diff --git a/test/unitTests/shim/telemetryClient.tests.ts b/test/unitTests/shim/telemetryClient.tests.ts index fdb9f75e..5d5ce0ac 100644 --- a/test/unitTests/shim/telemetryClient.tests.ts +++ b/test/unitTests/shim/telemetryClient.tests.ts @@ -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; @@ -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 () => {