@@ -10,6 +10,9 @@ import http = require("http");
1010import https = require( "https" ) ;
1111import { DistributedTracingModes } from '../../../applicationinsights' ;
1212import { checkWarnings } from './testUtils' ;
13+ import { BatchLogRecordProcessor , ConsoleLogRecordExporter } from '@opentelemetry/sdk-logs' ;
14+ import { BatchSpanProcessor , ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base' ;
15+ import { Resource } from '@opentelemetry/resources' ;
1316
1417class TestTokenCredential implements azureCoreAuth . TokenCredential {
1518 private _expiresOn : Date ;
@@ -81,7 +84,7 @@ describe("shim/configuration/config", () => {
8184 "winston" : { "enabled" : true } ,
8285 "console" : { "enabled" : true } ,
8386 } ) ,
84- "wrong instrumentationOptions" ) ;
87+ "wrong instrumentationOptions" ) ;
8588 assert . equal ( JSON . stringify ( options . instrumentationOptions . bunyan ) , JSON . stringify ( { enabled : true } ) , "wrong bunyan setting" ) ;
8689 assert . equal ( options . enableAutoCollectExceptions , true , "wrong enableAutoCollectExceptions" ) ;
8790 assert . equal ( options . enableAutoCollectPerformance , true , "wrong enableAutoCollectPerformance" ) ;
@@ -111,6 +114,31 @@ describe("shim/configuration/config", () => {
111114 assert . equal ( options . samplingRatio , 0 , "wrong samplingRatio" ) ;
112115 } ) ;
113116
117+
118+ it ( "should allow customization of Azure Monitor Distro configuration" , ( ) => {
119+ let spanProcessors = [ new BatchSpanProcessor ( new ConsoleSpanExporter ( ) ) ] ;
120+ let logRecordProcessors = [ new BatchLogRecordProcessor ( new ConsoleLogRecordExporter ) ] ;
121+ let resource = new Resource ( { } ) ;
122+ const config = new Config ( connectionString ) ;
123+ config . azureMonitorOpenTelemetryOptions = {
124+ resource : resource ,
125+ enableTraceBasedSamplingForLogs : false ,
126+ enableLiveMetrics : false ,
127+ enableStandardMetrics : false ,
128+ logRecordProcessors : logRecordProcessors ,
129+ spanProcessors : spanProcessors
130+ } ;
131+
132+ let options = config . parseConfig ( ) ;
133+ assert . equal ( options . resource , resource , "wrong resource" ) ;
134+ assert . equal ( options . enableTraceBasedSamplingForLogs , false , "wrong enableTraceBasedSamplingForLogs" ) ;
135+ assert . equal ( options . enableLiveMetrics , false , "wrong enableTraceBasedSamplingForLogs" ) ;
136+ assert . equal ( options . enableStandardMetrics , false , "wrong enableTraceBasedSamplingForLogs" ) ;
137+ assert . equal ( options . logRecordProcessors , logRecordProcessors , "wrong logRecordProcessors" ) ;
138+ assert . equal ( options . spanProcessors , spanProcessors , "wrong spanProcessors" ) ;
139+ } ) ;
140+
141+
114142 it ( "should activate DEBUG internal logger" , ( ) => {
115143 const env = < { [ id : string ] : string } > { } ;
116144 process . env = env ;
@@ -151,15 +179,15 @@ describe("shim/configuration/config", () => {
151179 "postgreSql" : { "enabled" : false } ,
152180 "bunyan" : { "enabled" : false } ,
153181 "winston" : { "enabled" : false } ,
154- "console" :{ "enabled" : false } ,
182+ "console" : { "enabled" : false } ,
155183 } ) ) ;
156184 } ) ;
157185
158186 it ( "should disable specific instrumentations when noPatchModules is set" , ( ) => {
159187 const config = new Config ( connectionString ) ;
160188 config . noPatchModules = "azuresdk,mongodb-core,redis,pg-pool" ;
161189 let options = config . parseConfig ( ) ;
162- assert . equal ( JSON . stringify ( options . instrumentationOptions ) , JSON . stringify ( {
190+ assert . equal ( JSON . stringify ( options . instrumentationOptions ) , JSON . stringify ( {
163191 http : { enabled : true } ,
164192 azureSdk : { enabled : false } ,
165193 mongoDb : { enabled : false } ,
@@ -326,7 +354,7 @@ describe("shim/configuration/config", () => {
326354 it ( "should warn if web instrumentations are set" , ( ) => {
327355 const config = new Config ( connectionString ) ;
328356 const warnings = config [ "_configWarnings" ] ;
329- config . webInstrumentationConfig = [ { name : "test" , value : true } ] ;
357+ config . webInstrumentationConfig = [ { name : "test" , value : true } ] ;
330358 config . webInstrumentationSrc = "test" ;
331359 config . parseConfig ( ) ;
332360 assert . ok ( checkWarnings ( "The webInstrumentation config and src options are not supported by the shim." , warnings ) , "warning was not raised" ) ;
0 commit comments