Skip to content

Commit 7ace8bc

Browse files
authored
Auto-enable Console in Auto-Instrumentation for App Service (#1479)
* Auto-enable console in app service auto-instrumentation. * Fix tests.
1 parent d92bb96 commit 7ace8bc

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/agent/appServicesLoader.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ import { EtwDiagnosticLogger } from './diagnostics/etwDiagnosticLogger';
1414
import { FileWriter } from "./diagnostics/writers/fileWriter";
1515
import { StatusLogger } from "./diagnostics/statusLogger";
1616
import { AgentLoader } from "./agentLoader";
17+
import { InstrumentationOptions } from '../types';
1718

1819
export class AppServicesLoader extends AgentLoader {
1920

2021
constructor() {
2122
super();
2223
if (this._canLoad) {
24+
(this._options.instrumentationOptions as InstrumentationOptions) = {
25+
...this._options.instrumentationOptions,
26+
console: { enabled: true },
27+
bunyan: { enabled: true },
28+
winston: { enabled: true },
29+
}
30+
2331
// Azure App Services specific configuration
2432
const resourceAttributes: Attributes = {};
2533
if (process.env.WEBSITE_SITE_NAME) {

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export interface AzureMonitorOpenTelemetryOptions extends DistroOptions {
3838
export interface InstrumentationOptions extends DistroInstrumentationOptions {
3939
/** Console Instrumentation Config */
4040
console?: InstrumentationConfig & { logSendingLevel?: SeverityNumber };
41+
/** Bunyan Instrumentation Config */
42+
bunyan?: InstrumentationConfig;
43+
/** Winston Instrumentation Config */
44+
winston?: InstrumentationConfig;
4145
}
4246

4347
/**

test/unitTests/agent/appServicesLoader.tests.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import sinon from "sinon";
44
import { AppServicesLoader } from "../../../src/agent/appServicesLoader";
55
import { DiagnosticLogger } from "../../../src/agent/diagnostics/diagnosticLogger";
66
import { FileWriter } from "../../../src/agent/diagnostics/writers/fileWriter";
7+
import { InstrumentationOptions } from "../../../src/types";
78
import {
89
SEMRESATTRS_SERVICE_INSTANCE_ID,
910
SEMRESATTRS_SERVICE_NAME,
@@ -98,4 +99,23 @@ describe("agent/AppServicesLoader", () => {
9899
"testRole"
99100
);
100101
});
102+
103+
it("should enable console, bunyan, and winston logging instrumentations", () => {
104+
const env = {
105+
["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333",
106+
["HOME"]: "c:",
107+
};
108+
process.env = env;
109+
const agent = new AppServicesLoader();
110+
111+
// Verify that logging instrumentations are enabled
112+
const instrumentationOptions = agent["_options"].instrumentationOptions as InstrumentationOptions;
113+
assert.ok(instrumentationOptions, "instrumentationOptions should be present");
114+
assert.ok(instrumentationOptions.console, "console instrumentation should be present");
115+
assert.equal(instrumentationOptions.console.enabled, true, "console instrumentation should be enabled");
116+
assert.ok(instrumentationOptions.bunyan, "bunyan instrumentation should be present");
117+
assert.equal(instrumentationOptions.bunyan.enabled, true, "bunyan instrumentation should be enabled");
118+
assert.ok(instrumentationOptions.winston, "winston instrumentation should be present");
119+
assert.equal(instrumentationOptions.winston.enabled, true, "winston instrumentation should be enabled");
120+
});
101121
});

0 commit comments

Comments
 (0)