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

Add Support for Tracking Shim Usage in Statsbeat & Fix Proxy Settings Issue #1331

Merged
merged 8 commits into from
May 30, 2024
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";

import { AutoCollectLogs } from "./logs/autoCollectLogs";
import { AutoCollectExceptions } from "./logs/exceptions";
import { AzureMonitorOpenTelemetryOptions } from "./types";
import { AZURE_MONITOR_STATSBEAT_FEATURES, AzureMonitorOpenTelemetryOptions } from "./types";
import { ApplicationInsightsConfig } from "./shared/configuration/config";
import { LogApi } from "./shim/logsApi";
import { PerformanceCounterMetrics } from "./metrics/performanceCounters";
import { AzureMonitorSpanProcessor } from "./traces/spanProcessor";
import { StatsbeatFeature, StatsbeatInstrumentation } from "./shim/types";

let autoCollectLogs: AutoCollectLogs;
let exceptions: AutoCollectExceptions;
Expand All @@ -28,6 +29,11 @@ let perfCounters: PerformanceCounterMetrics;
* @param options Configuration
*/
export function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions) {
// Must set statsbeat features before they are read by the distro
process.env[AZURE_MONITOR_STATSBEAT_FEATURES] = JSON.stringify({
JacksonWeber marked this conversation as resolved.
Show resolved Hide resolved
instrumentation: StatsbeatInstrumentation.NONE,
feature: StatsbeatFeature.SHIM
});
distroUseAzureMonitor(options);
const internalConfig = new ApplicationInsightsConfig(options);
const logApi = new LogApi(logs.getLogger("ApplicationInsightsLogger"));
Expand Down
2 changes: 0 additions & 2 deletions src/shim/shim-jsonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export class ShimJsonConfig implements IJsonConfig {
constructor() {
// Load environment variables first
this.connectionString = process.env[ENV_connectionString];
this.proxyHttpUrl = process.env[ENV_http_proxy];
this.proxyHttpsUrl = process.env[ENV_https_proxy];
this.noDiagnosticChannel = !!process.env[ENV_noDiagnosticChannel];
this.noHttpAgentKeepAlive = !!process.env[ENV_noHttpAgentKeepAlive];
this.noPatchModules = process.env[ENV_noPatchModules] || "";
Expand Down
29 changes: 28 additions & 1 deletion src/shim/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,31 @@ export interface IWebInstrumentationConfig {
* value provided to replace the default config value above
*/
value: string | boolean | number;
}
}

/**
* Statsbeat feature bit flags
*/
export enum StatsbeatFeature {
NONE = 0,
DISK_RETRY = 1,
AAD_HANDLING = 2,
BROWSER_SDK_LOADER = 4,
DISTRO = 8,
LIVE_METRICS = 16,
SHIM = 32,
}

/**
* Statsbeat instrumentation bit flags
*/
export enum StatsbeatInstrumentation {
NONE = 0,
AZURE_CORE_TRACING = 1,
MONGODB = 2,
MYSQL = 4,
REDIS = 8,
POSTGRES = 16,
BUNYAN = 32,
WINSTON = 64,
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OTLPExporterNodeConfigBase } from "@opentelemetry/otlp-exporter-base";

export const APPLICATION_INSIGHTS_OPENTELEMETRY_VERSION = "3.1.0";
export const DEFAULT_ROLE_NAME = "Web";
export const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";

/**
* Azure Monitor OpenTelemetry Options
Expand Down
4 changes: 0 additions & 4 deletions test/unitTests/shim/jsonConfig.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ describe("Json Config", () => {
const env = <{ [id: string]: string }>{};
env["APPLICATIONINSIGHTS_CONNECTION_STRING"] = "TestConnectionString";
env["APPLICATION_INSIGHTS_NO_PATCH_MODULES"] = "azuresdk";
env["http_proxy"] = "testProxyHttpUrl2";
env["https_proxy"] = "testProxyHttpsUrl2";
env["APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL"] = "disabled";
env["APPLICATION_INSIGHTS_NO_HTTP_AGENT_KEEP_ALIVE"] = "disabled";
env["APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_ENABLED"] = "true";
Expand All @@ -77,8 +75,6 @@ describe("Json Config", () => {
process.env = env;
const config = ShimJsonConfig.getInstance();
assert.equal(config.connectionString, "TestConnectionString");
assert.equal(config.proxyHttpUrl, "testProxyHttpUrl2");
assert.equal(config.proxyHttpsUrl, "testProxyHttpsUrl2");
assert.equal(config.noDiagnosticChannel, true, "wrong noDiagnosticChannel");
assert.equal(config.noHttpAgentKeepAlive, true, "wrong noHttpAgentKeepAlive");
assert.equal(config.noPatchModules, "azuresdk");
Expand Down
Loading