Skip to content

Commit

Permalink
[Azure Monitor OpenTelemetry Distro] Rename azureMonitorExporterConfig (
Browse files Browse the repository at this point in the history
#27063)

Addressing API review requested changes
  • Loading branch information
hectorhdzg authored Sep 8, 2023
1 parent 337b850 commit 8c6a412
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Resource } from '@opentelemetry/resources';

// @public
export interface AzureMonitorOpenTelemetryOptions {
azureMonitorExporterConfig?: AzureMonitorExporterOptions;
azureMonitorExporterOptions?: AzureMonitorExporterOptions;
instrumentationOptions?: InstrumentationOptions;
resource?: Resource;
samplingRatio?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as dotenv from "dotenv";
dotenv.config();

const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterConfig: {
azureMonitorExporterOptions: {
connectionString:
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as dotenv from "dotenv";
dotenv.config();

const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterConfig: {
azureMonitorExporterOptions: {
connectionString:
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/monitor-opentelemetry/src/logs/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class LogHandler {
resource: this._config.resource,
};
this._loggerProvider = new LoggerProvider(loggerProviderConfig);
this._azureExporter = new AzureMonitorLogExporter(this._config.azureMonitorExporterConfig);
this._azureExporter = new AzureMonitorLogExporter(this._config.azureMonitorExporterOptions);
// Log Processor could be configured through env variables
// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#batch-logrecord-processor
this._logRecordProcessor = new BatchLogRecordProcessor(this._azureExporter);
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/monitor-opentelemetry/src/metrics/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class MetricHandler {
resource: this._config.resource,
};
this._meterProvider = new MeterProvider(meterProviderConfig);
this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterConfig);
this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
let metricReaderOptions: PeriodicExportingMetricReaderOptions = {
exporter: this._azureExporter as any,
exportIntervalMillis: options?.collectionInterval || this._collectionInterval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class StandardMetrics {
resource: this._config.resource,
};
this._meterProvider = new MeterProvider(meterProviderConfig);
this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterConfig);
this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
const metricReaderOptions: PeriodicExportingMetricReaderOptions = {
exporter: this._azureExporter as any,
exportIntervalMillis: options?.collectionInterval || this._collectionInterval,
Expand Down
16 changes: 8 additions & 8 deletions sdk/monitor/monitor-opentelemetry/src/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class InternalConfig implements AzureMonitorOpenTelemetryOptions {
/** The rate of telemetry items tracked that should be transmitted (Default 1.0) */
public samplingRatio: number;
/** Azure Monitor Exporter Configuration */
public azureMonitorExporterConfig: AzureMonitorExporterOptions;
public azureMonitorExporterOptions: AzureMonitorExporterOptions;
/**
* OpenTelemetry Instrumentations configuration included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)
*/
Expand All @@ -43,7 +43,7 @@ export class InternalConfig implements AzureMonitorOpenTelemetryOptions {
*/
constructor(options?: AzureMonitorOpenTelemetryOptions) {
// Default values
this.azureMonitorExporterConfig = {};
this.azureMonitorExporterOptions = {};
this.samplingRatio = 1;
this.instrumentationOptions = {
http: { enabled: true },
Expand All @@ -61,9 +61,9 @@ export class InternalConfig implements AzureMonitorOpenTelemetryOptions {
// This will take precedence over other settings
if (options) {
// Merge default with provided options
this.azureMonitorExporterConfig = Object.assign(
this.azureMonitorExporterConfig,
options.azureMonitorExporterConfig
this.azureMonitorExporterOptions = Object.assign(
this.azureMonitorExporterOptions,
options.azureMonitorExporterOptions
);
this.instrumentationOptions = Object.assign(
this.instrumentationOptions,
Expand All @@ -80,9 +80,9 @@ export class InternalConfig implements AzureMonitorOpenTelemetryOptions {
this.samplingRatio =
jsonConfig.samplingRatio !== undefined ? jsonConfig.samplingRatio : this.samplingRatio;

this.azureMonitorExporterConfig = Object.assign(
this.azureMonitorExporterConfig,
jsonConfig.azureMonitorExporterConfig
this.azureMonitorExporterOptions = Object.assign(
this.azureMonitorExporterOptions,
jsonConfig.azureMonitorExporterOptions
);
this.instrumentationOptions = Object.assign(
this.instrumentationOptions,
Expand Down
4 changes: 2 additions & 2 deletions sdk/monitor/monitor-opentelemetry/src/shared/jsonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class JsonConfig implements AzureMonitorOpenTelemetryOptions {
/** The rate of telemetry items tracked that should be transmitted (Default 1.0) */
public samplingRatio?: number;
/** Azure Monitor Exporter Configuration */
public azureMonitorExporterConfig?: AzureMonitorExporterOptions;
public azureMonitorExporterOptions?: AzureMonitorExporterOptions;
/**
* OpenTelemetry Instrumentations configuration included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)
*/
Expand Down Expand Up @@ -69,7 +69,7 @@ export class JsonConfig implements AzureMonitorOpenTelemetryOptions {
}
try {
const jsonConfig: AzureMonitorOpenTelemetryOptions = JSON.parse(jsonString);
this.azureMonitorExporterConfig = jsonConfig.azureMonitorExporterConfig;
this.azureMonitorExporterOptions = jsonConfig.azureMonitorExporterOptions;
this.samplingRatio = jsonConfig.samplingRatio;
this.instrumentationOptions = jsonConfig.instrumentationOptions;
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/monitor-opentelemetry/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSIO
*/
export interface AzureMonitorOpenTelemetryOptions {
/** Azure Monitor Exporter Configuration */
azureMonitorExporterConfig?: AzureMonitorExporterOptions;
azureMonitorExporterOptions?: AzureMonitorExporterOptions;
/** OpenTelemetry Resource */
resource?: Resource;
/** The rate of telemetry items tracked that should be transmitted (Default 1.0) */
Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/monitor-opentelemetry/src/traces/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TraceHandler {
forceFlushTimeoutMillis: 30000,
};
this._tracerProvider = new NodeTracerProvider(tracerConfig);
this._azureExporter = new AzureMonitorTraceExporter(this._config.azureMonitorExporterConfig);
this._azureExporter = new AzureMonitorTraceExporter(this._config.azureMonitorExporterOptions);
const bufferConfig: BufferConfig = {
maxExportBatchSize: 512,
scheduledDelayMillis: 5000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe("LogHandler", () => {
let exportStub: sinon.SinonStub;
let metricHandler: MetricHandler;
const _config = new InternalConfig();
if (_config.azureMonitorExporterConfig) {
_config.azureMonitorExporterConfig.connectionString =
if (_config.azureMonitorExporterOptions) {
_config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Licensed under the MIT license.

import * as assert from "assert";
import { useAzureMonitor } from "../../../src/index";
import { InternalConfig } from "../../../src/shared/config";
import { useAzureMonitor, AzureMonitorOpenTelemetryOptions } from "../../../src/index";

describe("Main functions", () => {
it("useAzureMonitor", () => {
let config = new InternalConfig();
config.azureMonitorExporterConfig = {
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000",
let config: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
connectionString: "InstrumentationKey=00000000-0000-0000-0000-000000000000",
},
};
useAzureMonitor(config);
assert.ok(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ describe("MetricHandler", () => {
let handler: MetricHandler;
let exportStub: sinon.SinonStub;
const _config = new InternalConfig();
if (_config.azureMonitorExporterConfig) {
_config.azureMonitorExporterConfig.connectionString =
if (_config.azureMonitorExporterOptions) {
_config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("#StandardMetricsHandler", () => {

before(() => {
const config = new InternalConfig();
config.azureMonitorExporterConfig.connectionString =
config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;";
autoCollect = new StandardMetrics(config, { collectionInterval: 100 });
exportStub = sinon.stub(autoCollect["_azureExporter"], "export").callsFake(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"azureMonitorExporterConfig": {
"azureMonitorExporterOptions": {
"connectionString": "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/",
"disableOfflineStorage": true,
"storageDirectory": "testPath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ describe("Library/Config", () => {
process.env = env;
const config = new InternalConfig();
assert.deepStrictEqual(
config.azureMonitorExporterConfig.connectionString,
config.azureMonitorExporterOptions.connectionString,
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
);
assert.deepStrictEqual(config.samplingRatio, 0.3, "Wrong samplingRatio");
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.disableOfflineStorage,
config.azureMonitorExporterOptions?.disableOfflineStorage,
true,
"Wrong disableOfflineStorage"
);
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.storageDirectory,
config.azureMonitorExporterOptions?.storageDirectory,
"testPath",
"Wrong storageDirectory"
);
Expand Down Expand Up @@ -91,12 +91,12 @@ describe("Library/Config", () => {
assert.deepStrictEqual(config.instrumentationOptions.redis?.enabled, false, "Wrong redis");
assert.deepStrictEqual(config.instrumentationOptions.redis4?.enabled, false, "Wrong redis4");
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.disableOfflineStorage,
config.azureMonitorExporterOptions?.disableOfflineStorage,
undefined,
"Wrong disableOfflineStorage"
);
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.storageDirectory,
config.azureMonitorExporterOptions?.storageDirectory,
undefined,
"Wrong storageDirectory"
);
Expand All @@ -111,32 +111,32 @@ describe("Library/Config", () => {

it("should initialize valid values", () => {
const config = new InternalConfig();
config.azureMonitorExporterConfig.connectionString =
config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
assert.ok(typeof config.azureMonitorExporterConfig?.connectionString === "string");
assert.ok(typeof config.azureMonitorExporterOptions?.connectionString === "string");
assert.ok(typeof config.samplingRatio === "number");
});

it("instrumentation key validation-valid key passed", () => {
const warnStub = sandbox.stub(console, "warn");
const config = new InternalConfig();
config.azureMonitorExporterConfig.connectionString =
config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
assert.ok(warnStub.notCalled, "warning was not raised");
});

it("instrumentation key validation-invalid key passed", () => {
const warnStub = sandbox.stub(console, "warn");
const config = new InternalConfig();
config.azureMonitorExporterConfig.connectionString =
config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111bbbb1ccc8dddeeeeffff3333";
assert.ok(warnStub.calledOn, "warning was raised");
});

it("instrumentation key validation-invalid key passed", () => {
const warnStub = sandbox.stub(console, "warn");
const config = new InternalConfig();
config.azureMonitorExporterConfig.connectionString = "abc";
config.azureMonitorExporterOptions.connectionString = "abc";
assert.ok(warnStub.calledOn, "warning was raised");
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Json Config", () => {
process.env = env;
const config = JsonConfig.getInstance();
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.connectionString,
config.azureMonitorExporterOptions?.connectionString,
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
);
});
Expand All @@ -58,7 +58,7 @@ describe("Json Config", () => {
process.env = env;
const config = JsonConfig.getInstance();
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.connectionString,
config.azureMonitorExporterOptions?.connectionString,
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
);
});
Expand All @@ -75,11 +75,11 @@ describe("Json Config", () => {
process.env = env;
const config = JsonConfig.getInstance();
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.connectionString,
config.azureMonitorExporterOptions?.connectionString,
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
);
assert.deepStrictEqual(config.azureMonitorExporterConfig?.disableOfflineStorage, true);
assert.deepStrictEqual(config.azureMonitorExporterConfig?.storageDirectory, "testPath");
assert.deepStrictEqual(config.azureMonitorExporterOptions?.disableOfflineStorage, true);
assert.deepStrictEqual(config.azureMonitorExporterOptions?.storageDirectory, "testPath");
assert.deepStrictEqual(config.samplingRatio, 0.3, "Wrong samplingRatio");
assert.deepStrictEqual(
config.instrumentationOptions?.azureSdk?.enabled,
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("Json Config", () => {
process.env = env;
const config = JsonConfig.getInstance();
assert.deepStrictEqual(
config.azureMonitorExporterConfig?.connectionString,
config.azureMonitorExporterOptions?.connectionString,
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;IngestionEndpoint=https://centralus-0.in.applicationinsights.azure.com/"
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("Library/AzureFunctionsHook", () => {
let Module = require("module");
let preInvocationCalled = false;
let config = new InternalConfig({});
config.azureMonitorExporterConfig.connectionString =
config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333;";
metricHandler = new MetricHandler(config);
handler = new TraceHandler(config, metricHandler);
Expand All @@ -105,7 +105,7 @@ describe("Library/AzureFunctionsHook", () => {
attributes: {},
},
};
let preInvocationContext: any = {
let testInvocationContext: any = {
inputs: [],
functionCallback: () => {
let span = trace.getTracer("testTracer").startSpan("test");
Expand All @@ -121,9 +121,9 @@ describe("Library/AzureFunctionsHook", () => {
invocationContext: ctx,
};
// Azure Functions should call preinvocation callback
callback(preInvocationContext);
callback(testInvocationContext);
// Azure Functions should call customer function callback
preInvocationContext.functionCallback(null, null);
testInvocationContext.functionCallback(null, null);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe("Library/TraceHandler", () => {

before(() => {
_config = new InternalConfig();
if (_config.azureMonitorExporterConfig) {
_config.azureMonitorExporterConfig.connectionString =
if (_config.azureMonitorExporterOptions) {
_config.azureMonitorExporterOptions.connectionString =
"InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333";
}
sandbox = sinon.createSandbox();
Expand Down

0 comments on commit 8c6a412

Please sign in to comment.