@@ -10,8 +10,19 @@ import {
1010 shutdownAzureMonitor ,
1111} from "../../../src/index" ;
1212import { MeterProvider } from "@opentelemetry/sdk-metrics" ;
13+ import { StatsbeatFeature , StatsbeatInstrumentation } from "../../../src/types" ;
1314
1415describe ( "Main functions" , ( ) => {
16+ let originalEnv : NodeJS . ProcessEnv ;
17+
18+ beforeEach ( ( ) => {
19+ originalEnv = process . env ;
20+ } ) ;
21+
22+ afterEach ( ( ) => {
23+ process . env = originalEnv ;
24+ } ) ;
25+
1526 after ( ( ) => {
1627 trace . disable ( ) ;
1728 metrics . disable ( ) ;
@@ -60,9 +71,41 @@ describe("Main functions", () => {
6071 } ,
6172 } ;
6273 useAzureMonitor ( config ) ;
63- assert . strictEqual (
64- process . env [ "AZURE_MONITOR_STATSBEAT_FEATURES" ] ,
65- JSON . stringify ( { instrumentation : 15 , feature : 4 } )
74+ let output = JSON . parse ( String ( process . env [ "AZURE_MONITOR_STATSBEAT_FEATURES" ] ) ) ;
75+ const features = Number ( output [ "feature" ] ) ;
76+ const instrumentations = Number ( output [ "instrumentation" ] ) ;
77+ assert . ok ( ! ( features & StatsbeatFeature . AAD_HANDLING ) , "AAD_HANDLING is set" ) ;
78+ assert . ok ( ! ( features & StatsbeatFeature . DISK_RETRY ) , "DISK_RETRY is set" ) ;
79+ assert . ok ( ! ( features & StatsbeatFeature . WEB_SNIPPET ) , "WEB_SNIPPET is set" ) ;
80+ assert . ok ( features & StatsbeatFeature . DISTRO , "DISTRO is not set" ) ;
81+ assert . ok (
82+ instrumentations & StatsbeatInstrumentation . AZURE_CORE_TRACING ,
83+ "AZURE_CORE_TRACING not set"
6684 ) ;
85+ assert . ok ( instrumentations & StatsbeatInstrumentation . MONGODB , "MONGODB not set" ) ;
86+ assert . ok ( instrumentations & StatsbeatInstrumentation . MYSQL , "MYSQL not set" ) ;
87+ assert . ok ( instrumentations & StatsbeatInstrumentation . POSTGRES , "POSTGRES not set" ) ;
88+ assert . ok ( instrumentations & StatsbeatInstrumentation . REDIS , "REDIS not set" ) ;
89+ } ) ;
90+
91+ it ( "should use statsbeat features if already available" , ( ) => {
92+ const env = < { [ id : string ] : string } > { } ;
93+ let current = 0 ;
94+ current |= StatsbeatFeature . AAD_HANDLING ;
95+ current |= StatsbeatFeature . DISK_RETRY ;
96+ env . AZURE_MONITOR_STATSBEAT_FEATURES = current . toString ( ) ;
97+ process . env = env ;
98+ let config : AzureMonitorOpenTelemetryOptions = {
99+ azureMonitorExporterOptions : {
100+ connectionString : "InstrumentationKey=00000000-0000-0000-0000-000000000000" ,
101+ } ,
102+ } ;
103+ useAzureMonitor ( config ) ;
104+ let output = JSON . parse ( String ( process . env [ "AZURE_MONITOR_STATSBEAT_FEATURES" ] ) ) ;
105+ const numberOutput = Number ( output [ "feature" ] ) ;
106+ assert . ok ( numberOutput & StatsbeatFeature . AAD_HANDLING , "AAD_HANDLING not set" ) ;
107+ assert . ok ( numberOutput & StatsbeatFeature . DISK_RETRY , "DISK_RETRY not set" ) ;
108+ assert . ok ( numberOutput & StatsbeatFeature . DISTRO , "DISTRO not set" ) ;
109+ assert . ok ( ! ( numberOutput & StatsbeatFeature . WEB_SNIPPET ) , "WEB_SNIPPET is set" ) ;
67110 } ) ;
68111} ) ;
0 commit comments