Skip to content

Commit

Permalink
[Beta] Update Unsupported Messages & Remove Deprecated SemAttrs (#1306)
Browse files Browse the repository at this point in the history
* Update unsupppoted message and semantic attribute imports.

* Update warning messages.
  • Loading branch information
JacksonWeber committed Apr 15, 2024
1 parent fae2d2e commit c42914c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 38 deletions.
40 changes: 20 additions & 20 deletions src/shim/shim-config.ts
Expand Up @@ -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";

Expand Down Expand Up @@ -302,68 +302,68 @@ 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] ||
process.env[legacy_ENV_iKey] ||
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;
}
Expand Down
43 changes: 27 additions & 16 deletions src/shim/telemetryClient.ts
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 All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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}`);
}

/**
Expand All @@ -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}`);
}

/*
Expand Down Expand Up @@ -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}`);
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/shim/types.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unitTests/shim/telemetryClient.tests.ts
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

0 comments on commit c42914c

Please sign in to comment.