Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/agent/appServicesLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ import { EtwDiagnosticLogger } from './diagnostics/etwDiagnosticLogger';
import { FileWriter } from "./diagnostics/writers/fileWriter";
import { StatusLogger } from "./diagnostics/statusLogger";
import { AgentLoader } from "./agentLoader";
import { InstrumentationOptions } from '../types';

export class AppServicesLoader extends AgentLoader {

constructor() {
super();
if (this._canLoad) {
(this._options.instrumentationOptions as InstrumentationOptions) = {
...this._options.instrumentationOptions,
console: { enabled: true },
bunyan: { enabled: true },
winston: { enabled: true },
}

// Azure App Services specific configuration
const resourceAttributes: Attributes = {};
if (process.env.WEBSITE_SITE_NAME) {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export interface AzureMonitorOpenTelemetryOptions extends DistroOptions {
export interface InstrumentationOptions extends DistroInstrumentationOptions {
/** Console Instrumentation Config */
console?: InstrumentationConfig & { logSendingLevel?: SeverityNumber };
/** Bunyan Instrumentation Config */
bunyan?: InstrumentationConfig;
/** Winston Instrumentation Config */
winston?: InstrumentationConfig;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/unitTests/agent/appServicesLoader.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import sinon from "sinon";
import { AppServicesLoader } from "../../../src/agent/appServicesLoader";
import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger";
import { FileWriter } from "../../../src/agent/diagnostics/writers/fileWriter";
import { InstrumentationOptions } from "../../../src/types";
import {
SEMRESATTRS_SERVICE_INSTANCE_ID,
SEMRESATTRS_SERVICE_NAME,
Expand Down Expand Up @@ -98,4 +99,23 @@ describe("agent/AppServicesLoader", () => {
"testRole"
);
});

it("should enable console, bunyan, and winston logging instrumentations", () => {
const env = {
["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333",
["HOME"]: "c:",
};
process.env = env;
const agent = new AppServicesLoader();

// Verify that logging instrumentations are enabled
const instrumentationOptions = agent["_options"].instrumentationOptions as InstrumentationOptions;
assert.ok(instrumentationOptions, "instrumentationOptions should be present");
assert.ok(instrumentationOptions.console, "console instrumentation should be present");
assert.equal(instrumentationOptions.console.enabled, true, "console instrumentation should be enabled");
assert.ok(instrumentationOptions.bunyan, "bunyan instrumentation should be present");
assert.equal(instrumentationOptions.bunyan.enabled, true, "bunyan instrumentation should be enabled");
assert.ok(instrumentationOptions.winston, "winston instrumentation should be present");
assert.equal(instrumentationOptions.winston.enabled, true, "winston instrumentation should be enabled");
});
});
Loading