Skip to content

Commit f8137a7

Browse files
authored
Connection string overrides (#2471)
* Add connectionStringOverrides * Constants * more * Smoke tests * More * Fix * More ikey -> connection string * Remove setInstrumentationKey from classic sdk * TODO heya * is * Rename * Rename * Reuse * Review * Unused * Unused * Rename
1 parent d7a916f commit f8137a7

File tree

93 files changed

+2143
-1154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2143
-1154
lines changed

agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/BytecodeUtil.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void trackMetric(
6565
null,
6666
properties,
6767
Collections.emptyMap(),
68+
null,
6869
null);
6970
}
7071
});
@@ -77,9 +78,11 @@ public static void trackEvent(
7778
Map<String, String> properties,
7879
Map<String, String> tags,
7980
Map<String, Double> metrics,
81+
@Nullable String connectionString,
8082
@Nullable String instrumentationKey) {
8183
if (delegate != null) {
82-
delegate.trackEvent(timestamp, name, properties, tags, metrics, instrumentationKey);
84+
delegate.trackEvent(
85+
timestamp, name, properties, tags, metrics, connectionString, instrumentationKey);
8386
}
8487
}
8588

@@ -94,6 +97,7 @@ public static void trackMetric(
9497
@Nullable Double stdDev,
9598
Map<String, String> properties,
9699
Map<String, String> tags,
100+
@Nullable String connectionString,
97101
@Nullable String instrumentationKey) {
98102
if (delegate != null) {
99103
delegate.trackMetric(
@@ -107,6 +111,7 @@ public static void trackMetric(
107111
stdDev,
108112
properties,
109113
tags,
114+
connectionString,
110115
instrumentationKey);
111116
}
112117
}
@@ -124,6 +129,7 @@ public static void trackDependency(
124129
Map<String, String> properties,
125130
Map<String, String> tags,
126131
Map<String, Double> metrics,
132+
@Nullable String connectionString,
127133
@Nullable String instrumentationKey) {
128134
if (delegate != null) {
129135
delegate.trackDependency(
@@ -139,6 +145,7 @@ public static void trackDependency(
139145
properties,
140146
tags,
141147
metrics,
148+
connectionString,
142149
instrumentationKey);
143150
}
144151
}
@@ -151,10 +158,19 @@ public static void trackPageView(
151158
Map<String, String> properties,
152159
Map<String, String> tags,
153160
Map<String, Double> metrics,
161+
@Nullable String connectionString,
154162
@Nullable String instrumentationKey) {
155163
if (delegate != null) {
156164
delegate.trackPageView(
157-
timestamp, name, uri, totalMillis, properties, tags, metrics, instrumentationKey);
165+
timestamp,
166+
name,
167+
uri,
168+
totalMillis,
169+
properties,
170+
tags,
171+
metrics,
172+
connectionString,
173+
instrumentationKey);
158174
}
159175
}
160176

@@ -164,9 +180,17 @@ public static void trackTrace(
164180
int severityLevel,
165181
Map<String, String> properties,
166182
Map<String, String> tags,
183+
@Nullable String connectionString,
167184
@Nullable String instrumentationKey) {
168185
if (delegate != null) {
169-
delegate.trackTrace(timestamp, message, severityLevel, properties, tags, instrumentationKey);
186+
delegate.trackTrace(
187+
timestamp,
188+
message,
189+
severityLevel,
190+
properties,
191+
tags,
192+
connectionString,
193+
instrumentationKey);
170194
}
171195
}
172196

@@ -182,6 +206,7 @@ public static void trackRequest(
182206
Map<String, String> properties,
183207
Map<String, String> tags,
184208
Map<String, Double> metrics,
209+
@Nullable String connectionString,
185210
@Nullable String instrumentationKey) {
186211
if (delegate != null) {
187212
delegate.trackRequest(
@@ -196,6 +221,7 @@ public static void trackRequest(
196221
properties,
197222
tags,
198223
metrics,
224+
connectionString,
199225
instrumentationKey);
200226
}
201227
}
@@ -207,10 +233,18 @@ public static void trackException(
207233
Map<String, String> properties,
208234
Map<String, String> tags,
209235
Map<String, Double> metrics,
236+
@Nullable String connectionString,
210237
@Nullable String instrumentationKey) {
211238
if (delegate != null) {
212239
delegate.trackException(
213-
timestamp, throwable, severityLevel, properties, tags, metrics, instrumentationKey);
240+
timestamp,
241+
throwable,
242+
severityLevel,
243+
properties,
244+
tags,
245+
metrics,
246+
connectionString,
247+
instrumentationKey);
214248
}
215249
}
216250

@@ -225,6 +259,7 @@ public static void trackAvailability(
225259
Map<String, String> properties,
226260
Map<String, String> tags,
227261
Map<String, Double> metrics,
262+
@Nullable String connectionString,
228263
@Nullable String instrumentationKey) {
229264
if (delegate != null) {
230265
delegate.trackAvailability(
@@ -238,6 +273,7 @@ public static void trackAvailability(
238273
properties,
239274
tags,
240275
metrics,
276+
connectionString,
241277
instrumentationKey);
242278
}
243279
}
@@ -322,6 +358,7 @@ void trackEvent(
322358
Map<String, String> properties,
323359
Map<String, String> tags,
324360
Map<String, Double> metrics,
361+
@Nullable String connectionString,
325362
@Nullable String instrumentationKey);
326363

327364
void trackMetric(
@@ -335,6 +372,7 @@ void trackMetric(
335372
@Nullable Double stdDev,
336373
Map<String, String> properties,
337374
Map<String, String> tags,
375+
@Nullable String connectionString,
338376
@Nullable String instrumentationKey);
339377

340378
void trackDependency(
@@ -350,6 +388,7 @@ void trackDependency(
350388
Map<String, String> properties,
351389
Map<String, String> tags,
352390
Map<String, Double> metrics,
391+
@Nullable String connectionString,
353392
@Nullable String instrumentationKey);
354393

355394
void trackPageView(
@@ -360,6 +399,7 @@ void trackPageView(
360399
Map<String, String> properties,
361400
Map<String, String> tags,
362401
Map<String, Double> metrics,
402+
@Nullable String connectionString,
363403
@Nullable String instrumentationKey);
364404

365405
void trackTrace(
@@ -368,6 +408,7 @@ void trackTrace(
368408
int severityLevel,
369409
Map<String, String> properties,
370410
Map<String, String> tags,
411+
@Nullable String connectionString,
371412
@Nullable String instrumentationKey);
372413

373414
void trackRequest(
@@ -382,6 +423,7 @@ void trackRequest(
382423
Map<String, String> properties,
383424
Map<String, String> tags,
384425
Map<String, Double> metrics,
426+
@Nullable String connectionString,
385427
@Nullable String instrumentationKey);
386428

387429
void trackException(
@@ -391,6 +433,7 @@ void trackException(
391433
Map<String, String> properties,
392434
Map<String, String> tags,
393435
Map<String, Double> metrics,
436+
@Nullable String connectionString,
394437
@Nullable String instrumentationKey);
395438

396439
void trackAvailability(
@@ -404,6 +447,7 @@ void trackAvailability(
404447
Map<String, String> properties,
405448
Map<String, String> tags,
406449
Map<String, Double> metrics,
450+
@Nullable String connectionString,
407451
@Nullable String instrumentationKey);
408452

409453
void flush();

agent/agent-bootstrap/src/test/java/com/microsoft/applicationinsights/agent/bootstrap/diagnostics/status/StatusFileTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
4848
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
4949

50-
// FIXME (trask) failing in CI on deleting the the @TempDir
51-
@Disabled
50+
@Disabled("failing on CI when deleted the @TempDir")
5251
@ExtendWith(SystemStubsExtension.class)
5352
class StatusFileTests {
5453

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/classicsdk/BytecodeUtilImpl.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void trackEvent(
7676
Map<String, String> properties,
7777
Map<String, String> tags,
7878
Map<String, Double> measurements,
79+
@Nullable String connectionString,
7980
@Nullable String instrumentationKey) {
8081

8182
if (Strings.isNullOrEmpty(name)) {
@@ -97,9 +98,7 @@ public void trackEvent(
9798
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
9899
}
99100
selectivelySetTags(telemetryBuilder, tags);
100-
if (instrumentationKey != null) {
101-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
102-
}
101+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
103102

104103
track(telemetryBuilder, tags, true);
105104
}
@@ -117,6 +116,7 @@ public void trackMetric(
117116
@Nullable Double stdDev,
118117
Map<String, String> properties,
119118
Map<String, String> tags,
119+
@Nullable String connectionString,
120120
@Nullable String instrumentationKey) {
121121

122122
if (Strings.isNullOrEmpty(name)) {
@@ -145,9 +145,7 @@ public void trackMetric(
145145
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
146146
}
147147
selectivelySetTags(telemetryBuilder, tags);
148-
if (instrumentationKey != null) {
149-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
150-
}
148+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
151149

152150
track(telemetryBuilder, tags, false);
153151
}
@@ -166,6 +164,7 @@ public void trackDependency(
166164
Map<String, String> properties,
167165
Map<String, String> tags,
168166
Map<String, Double> measurements,
167+
@Nullable String connectionString,
169168
@Nullable String instrumentationKey) {
170169

171170
if (Strings.isNullOrEmpty(name)) {
@@ -201,9 +200,7 @@ public void trackDependency(
201200
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
202201
}
203202
selectivelySetTags(telemetryBuilder, tags);
204-
if (instrumentationKey != null) {
205-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
206-
}
203+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
207204

208205
track(telemetryBuilder, tags, true);
209206
}
@@ -217,6 +214,7 @@ public void trackPageView(
217214
Map<String, String> properties,
218215
Map<String, String> tags,
219216
Map<String, Double> measurements,
217+
@Nullable String connectionString,
220218
@Nullable String instrumentationKey) {
221219

222220
if (Strings.isNullOrEmpty(name)) {
@@ -243,9 +241,7 @@ public void trackPageView(
243241
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
244242
}
245243
selectivelySetTags(telemetryBuilder, tags);
246-
if (instrumentationKey != null) {
247-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
248-
}
244+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
249245

250246
track(telemetryBuilder, tags, true);
251247
}
@@ -257,6 +253,7 @@ public void trackTrace(
257253
int severityLevel,
258254
Map<String, String> properties,
259255
Map<String, String> tags,
256+
@Nullable String connectionString,
260257
@Nullable String instrumentationKey) {
261258
if (message == null) {
262259
return;
@@ -279,9 +276,7 @@ public void trackTrace(
279276
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
280277
}
281278
selectivelySetTags(telemetryBuilder, tags);
282-
if (instrumentationKey != null) {
283-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
284-
}
279+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
285280

286281
track(telemetryBuilder, tags, true);
287282
}
@@ -299,6 +294,7 @@ public void trackRequest(
299294
Map<String, String> properties,
300295
Map<String, String> tags,
301296
Map<String, Double> measurements,
297+
@Nullable String connectionString,
302298
@Nullable String instrumentationKey) {
303299
if (Strings.isNullOrEmpty(name)) {
304300
return;
@@ -334,9 +330,7 @@ public void trackRequest(
334330
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
335331
}
336332
selectivelySetTags(telemetryBuilder, tags);
337-
if (instrumentationKey != null) {
338-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
339-
}
333+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
340334

341335
track(telemetryBuilder, tags, true);
342336
}
@@ -349,6 +343,7 @@ public void trackException(
349343
Map<String, String> properties,
350344
Map<String, String> tags,
351345
Map<String, Double> measurements,
346+
@Nullable String connectionString,
352347
@Nullable String instrumentationKey) {
353348
if (throwable == null) {
354349
return;
@@ -375,9 +370,7 @@ public void trackException(
375370
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
376371
}
377372
selectivelySetTags(telemetryBuilder, tags);
378-
if (instrumentationKey != null) {
379-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
380-
}
373+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
381374

382375
track(telemetryBuilder, tags, true);
383376
}
@@ -394,6 +387,7 @@ public void trackAvailability(
394387
Map<String, String> properties,
395388
Map<String, String> tags,
396389
Map<String, Double> measurements,
390+
@Nullable String connectionString,
397391
@Nullable String instrumentationKey) {
398392

399393
if (Strings.isNullOrEmpty(name)) {
@@ -427,9 +421,7 @@ public void trackAvailability(
427421
telemetryBuilder.setTime(FormattedTime.offSetDateTimeFromNow());
428422
}
429423
selectivelySetTags(telemetryBuilder, tags);
430-
if (instrumentationKey != null) {
431-
telemetryBuilder.setInstrumentationKey(instrumentationKey);
432-
}
424+
setConnectionString(telemetryBuilder, connectionString, instrumentationKey);
433425

434426
track(telemetryBuilder, tags, false);
435427
}
@@ -544,6 +536,18 @@ private static void setOperationTagsFromTheCurrentSpan(
544536
}
545537
}
546538

539+
private static void setConnectionString(
540+
AbstractTelemetryBuilder telemetryBuilder,
541+
@Nullable String connectionString,
542+
@Nullable String instrumentationKey) {
543+
if (connectionString == null && instrumentationKey != null) {
544+
connectionString = "InstrumentationKey=" + instrumentationKey;
545+
}
546+
if (connectionString != null) {
547+
telemetryBuilder.setConnectionString(connectionString);
548+
}
549+
}
550+
547551
private static boolean sample(String operationId, double samplingPercentage) {
548552
if (samplingPercentage == 100) {
549553
// just an optimization

0 commit comments

Comments
 (0)