@@ -8,10 +8,12 @@ import { DiagnosticLogger } from "./DiagnosticLogger";
8
8
import Config = require( "../Library/Config" ) ;
9
9
import { DiagnosticLog , DiagnosticMessageId } from "./DataModel" ;
10
10
import * as PrefixHelpers from "../Library/PrefixHelper" ;
11
+ import Context = require( "../Library/Context" ) ;
11
12
12
13
// Private configuration vars
13
14
let _appInsights : typeof types | null ;
14
- let _prefix = "ud_" ; // Unknown, Default
15
+ let _prefix = `${ PrefixHelpers . getResourceProvider ( ) } ${ PrefixHelpers . getOsPrefix ( ) } ${ Constants . AttachTypePrefix . INTEGRATED_AUTO } _` ;
16
+ let _fullSdkVersion = `${ _prefix } node:${ Context . sdkVersion } ` ;
15
17
16
18
export const defaultConfig = new Config ( ) ; // Will read env variables, expose for Agent initialization
17
19
const _instrumentationKey = defaultConfig . instrumentationKey ;
@@ -30,14 +32,6 @@ export function setLogger(logger: DiagnosticLogger) {
30
32
return _logger = logger ;
31
33
}
32
34
33
- /**
34
- * Sets the string which is prefixed to the existing sdkVersion, e.g. `ad_`, `alr_`
35
- * @param prefix string prefix, including underscore. Defaults to `ud_`
36
- */
37
- export function setUsagePrefix ( prefix : string ) {
38
- _prefix = prefix ;
39
- }
40
-
41
35
export function setStatusLogger ( statusLogger : StatusLogger ) {
42
36
_statusLogger = statusLogger ;
43
37
}
@@ -89,13 +83,9 @@ export function setupAndStart(aadTokenCredential?: azureCoreAuth.TokenCredential
89
83
90
84
/** Sets the SDK version prefix in auto-attach scenarios */
91
85
const prefixInternalSdkVersion = function ( envelope : types . Contracts . Envelope , _contextObjects : Object ) {
92
- if ( _prefix === "ud_" ) {
93
- // If SDK version prefix is not set - set it using {RP}{OS}{Attach Type}_ pattern
94
- _prefix = `${ PrefixHelpers . getResourceProvider ( ) } ${ PrefixHelpers . getOsPrefix ( ) } ${ Constants . AttachTypePrefix . INTEGRATED_AUTO } _`
95
- }
86
+ // If SDK version prefix is not set - set it using {RP}{OS}{Attach Type}_ pattern
96
87
try {
97
- var appInsightsSDKVersion = _appInsights . defaultClient . context . keys . internalSdkVersion ;
98
- envelope . tags [ appInsightsSDKVersion ] = _prefix + envelope . tags [ appInsightsSDKVersion ] ;
88
+ envelope . tags [ appInsightsSDKVersion ] = _fullSdkVersion ;
99
89
} catch ( e ) {
100
90
const diagnosticLog : DiagnosticLog = {
101
91
message : "Error prefixing SDK version." ,
@@ -122,6 +112,7 @@ export function setupAndStart(aadTokenCredential?: azureCoreAuth.TokenCredential
122
112
123
113
// Instrument the SDK
124
114
_appInsights . setup ( ) ;
115
+ const appInsightsSDKVersion = _appInsights . defaultClient . context . keys . internalSdkVersion ;
125
116
126
117
// Azure Functions
127
118
if ( isAzureFunction ) {
@@ -195,6 +186,8 @@ export function setupAndStart(aadTokenCredential?: azureCoreAuth.TokenCredential
195
186
}
196
187
197
188
_appInsights . start ( ) ;
189
+ // Set the SDK verison in the context
190
+ _appInsights . defaultClient . context . tags [ appInsightsSDKVersion ] = _fullSdkVersion ;
198
191
// Add attach flag in Statsbeat
199
192
let statsbeat = _appInsights . defaultClient . getStatsbeat ( ) ;
200
193
if ( statsbeat ) {
0 commit comments