@@ -17,7 +17,7 @@ You can write and configure plug-ins for the Application Insights SDK to customi
17
17
18
18
Before you start:
19
19
20
- * Install the appropriate SDK for your application: [ ASP.NET] ( asp-net.md ) , [ ASP.NET Core] ( asp-net-core.md ) , [ Non HTTP/Worker for .NET/.NET Core] ( worker-service.md ) , [ Java ] ( ../../azure-monitor/app/java-get-started.md ) or [ JavaScript] ( javascript.md )
20
+ * Install the appropriate SDK for your application: [ ASP.NET] ( asp-net.md ) , [ ASP.NET Core] ( asp-net-core.md ) , [ Non HTTP/Worker for .NET/.NET Core] ( worker-service.md ) , or [ JavaScript] ( javascript.md )
21
21
22
22
<a name =" filtering " ></a >
23
23
@@ -81,8 +81,8 @@ Insert this snippet in ApplicationInsights.config:
81
81
```xml
82
82
< TelemetryProcessors >
83
83
< Add Type = " WebApplication9.SuccessfulDependencyFilter, WebApplication9" >
84
- < ! -- Set public property -- >
85
- < MyParamFromConfigFile > 2 - beta < / MyParamFromConfigFile >
84
+ < ! -- Set public property -- >
85
+ < MyParamFromConfigFile > 2 - beta < / MyParamFromConfigFile >
86
86
< / Add >
87
87
< / TelemetryProcessors >
88
88
```
@@ -200,7 +200,7 @@ public void Process(ITelemetry item)
200
200
``` JS
201
201
var filteringFunction = (envelope ) => {
202
202
if (envelope .data .someField === ' tobefilteredout' ) {
203
- return false ;
203
+ return false ;
204
204
}
205
205
206
206
return true ;
@@ -241,24 +241,24 @@ namespace MvcWebRole.Telemetry
241
241
*/
242
242
public class MyTelemetryInitializer : ITelemetryInitializer
243
243
{
244
- public void Initialize (ITelemetry telemetry )
245
- {
246
- var requestTelemetry = telemetry as RequestTelemetry ;
247
- // Is this a TrackRequest() ?
248
- if (requestTelemetry == null ) return ;
249
- int code ;
250
- bool parsed = Int32 .TryParse (requestTelemetry .ResponseCode , out code );
251
- if (! parsed ) return ;
252
- if (code >= 400 && code < 500 )
253
- {
254
- // If we set the Success property, the SDK won't change it:
255
- requestTelemetry .Success = true ;
256
-
257
- // Allow us to filter these requests in the portal:
258
- requestTelemetry .Properties [" Overridden400s" ] = " true" ;
259
- }
260
- // else leave the SDK to set the Success property
261
- }
244
+ public void Initialize (ITelemetry telemetry )
245
+ {
246
+ var requestTelemetry = telemetry as RequestTelemetry ;
247
+ // Is this a TrackRequest() ?
248
+ if (requestTelemetry == null ) return ;
249
+ int code ;
250
+ bool parsed = Int32 .TryParse (requestTelemetry .ResponseCode , out code );
251
+ if (! parsed ) return ;
252
+ if (code >= 400 && code < 500 )
253
+ {
254
+ // If we set the Success property, the SDK won't change it:
255
+ requestTelemetry .Success = true ;
256
+
257
+ // Allow us to filter these requests in the portal:
258
+ requestTelemetry .Properties [" Overridden400s" ] = " true" ;
259
+ }
260
+ // else leave the SDK to set the Success property
261
+ }
262
262
}
263
263
}
264
264
```
@@ -270,9 +270,9 @@ In ApplicationInsights.config:
270
270
``` xml
271
271
<ApplicationInsights >
272
272
<TelemetryInitializers >
273
- <!-- Fully qualified type name, assembly name: -->
274
- <Add Type =" MvcWebRole.Telemetry.MyTelemetryInitializer, MvcWebRole" />
275
- ...
273
+ <!-- Fully qualified type name, assembly name: -->
274
+ <Add Type =" MvcWebRole.Telemetry.MyTelemetryInitializer, MvcWebRole" />
275
+ ...
276
276
</TelemetryInitializers >
277
277
</ApplicationInsights >
278
278
```
@@ -304,67 +304,47 @@ For apps written using [ASP.NET Core](asp-net-core.md#adding-telemetryinitialize
304
304
services .AddSingleton <ITelemetryInitializer , MyTelemetryInitializer >();
305
305
}
306
306
```
307
-
308
- ### Java telemetry initializers
309
-
310
- [ Java SDK documentation] ( https://docs.microsoft.com/java/api/com.microsoft.applicationinsights.extensibility.telemetryinitializer?view=azure-java-stable )
311
-
312
- ``` Java
313
- public interface TelemetryInitializer
314
- { /* * Initializes properties of the specified object. * @param telemetry The {@link com.microsoft.applicationinsights.telemetry.Telemetry} to initialize. */
315
-
316
- void initialize (Telemetry telemetry ); }
317
- ```
318
-
319
- Then register the custom initializer in your applicationinsights.xml file.
320
-
321
- ``` xml
322
- <Add type =" mypackage.MyConfigurableContextInitializer" >
323
- <Param name =" some_config_property" value =" some_value" />
324
- </Add >
325
- ```
326
-
327
307
### JavaScript telemetry initializers
328
308
* JavaScript*
329
309
330
310
Insert a telemetry initializer immediately after the initialization code that you got from the portal:
331
311
332
312
``` JS
333
313
< script type= " text/javascript" >
334
- // ... initialization code
335
- ... ({
336
- instrumentationKey: " your instrumentation key"
337
- });
338
- window .appInsights = appInsights;
314
+ // ... initialization code
315
+ ... ({
316
+ instrumentationKey: " your instrumentation key"
317
+ });
318
+ window .appInsights = appInsights;
339
319
340
320
341
- // Adding telemetry initializer.
342
- // This is called whenever a new telemetry item
343
- // is created.
321
+ // Adding telemetry initializer.
322
+ // This is called whenever a new telemetry item
323
+ // is created.
344
324
345
- appInsights .queue .push (function () {
346
- appInsights .context .addTelemetryInitializer (function (envelope ) {
347
- var telemetryItem = envelope .data .baseData ;
325
+ appInsights .queue .push (function () {
326
+ appInsights .context .addTelemetryInitializer (function (envelope ) {
327
+ var telemetryItem = envelope .data .baseData ;
348
328
349
- // To check the telemetry items type - for example PageView:
350
- if (envelope .name == Microsoft .ApplicationInsights .Telemetry .PageView .envelopeType ) {
351
- // this statement removes url from all page view documents
352
- telemetryItem .url = " URL CENSORED" ;
353
- }
329
+ // To check the telemetry items type - for example PageView:
330
+ if (envelope .name == Microsoft .ApplicationInsights .Telemetry .PageView .envelopeType ) {
331
+ // this statement removes url from all page view documents
332
+ telemetryItem .url = " URL CENSORED" ;
333
+ }
354
334
355
- // To set custom properties:
356
- telemetryItem .properties = telemetryItem .properties || {};
357
- telemetryItem .properties [" globalProperty" ] = " boo" ;
335
+ // To set custom properties:
336
+ telemetryItem .properties = telemetryItem .properties || {};
337
+ telemetryItem .properties [" globalProperty" ] = " boo" ;
358
338
359
- // To set custom metrics:
360
- telemetryItem .measurements = telemetryItem .measurements || {};
361
- telemetryItem .measurements [" globalMetric" ] = 100 ;
362
- });
363
- });
339
+ // To set custom metrics:
340
+ telemetryItem .measurements = telemetryItem .measurements || {};
341
+ telemetryItem .measurements [" globalMetric" ] = 100 ;
342
+ });
343
+ });
364
344
365
- // End of inserted code.
345
+ // End of inserted code.
366
346
367
- appInsights .trackPageView ();
347
+ appInsights .trackPageView ();
368
348
< / script>
369
349
```
370
350
@@ -381,7 +361,7 @@ Telemetry processors in OpenCensus Python are simply callback functions called t
381
361
382
362
``` python
383
363
def callback_function (envelope ):
384
- envelope.tags[' ai.cloud.role' ] = ' new_role_name.py'
364
+ envelope.tags[' ai.cloud.role' ] = ' new_role_name.py'
385
365
```
386
366
387
367
``` python
@@ -394,8 +374,8 @@ logger = logging.getLogger(__name__)
394
374
395
375
# Callback function to append '_hello' to each log message telemetry
396
376
def callback_function (envelope ):
397
- envelope.data.baseData.message += ' _hello'
398
- return True
377
+ envelope.data.baseData.message += ' _hello'
378
+ return True
399
379
400
380
handler = AzureLogHandler(connection_string = ' InstrumentationKey=<your-instrumentation_key-here>' )
401
381
handler.add_telemetry_processor(callback_function)
@@ -415,11 +395,11 @@ config_integration.trace_integrations(['requests'])
415
395
416
396
# Callback function to add os_type: linux to span properties
417
397
def callback_function (envelope ):
418
- envelope.data.baseData.properties[' os_type' ] = ' linux'
419
- return True
398
+ envelope.data.baseData.properties[' os_type' ] = ' linux'
399
+ return True
420
400
421
401
exporter = AzureExporter(
422
- connection_string = ' InstrumentationKey=<your-instrumentation-key-here>'
402
+ connection_string = ' InstrumentationKey=<your-instrumentation-key-here>'
423
403
)
424
404
exporter.add_telemetry_processor(callback_function)
425
405
tracer = Tracer(exporter = exporter, sampler = ProbabilitySampler(1.0 ))
0 commit comments