@@ -12,7 +12,7 @@ ms.workload: tbd
12
12
ms.tgt_pltfrm : ibiza
13
13
ms.devlang : na
14
14
ms.topic : conceptual
15
- ms.date : 12/18/2017
15
+ ms.date : 08/07/2018
16
16
ms.reviewer : lmolkova
17
17
ms.author : mbullwin
18
18
@@ -125,59 +125,72 @@ TelemetryConfiguration.Active.TelemetryInitializers.Add(new HttpDependenciesPars
125
125
#### Full example
126
126
127
127
``` csharp
128
- static void Main (string [] args )
128
+ using Microsoft .ApplicationInsights ;
129
+ using Microsoft .ApplicationInsights .DependencyCollector ;
130
+ using Microsoft .ApplicationInsights .Extensibility ;
131
+ using System .Net .Http ;
132
+ using System .Threading .Tasks ;
133
+
134
+ namespace ConsoleApp
129
135
{
130
- TelemetryConfiguration configuration = TelemetryConfiguration .Active ;
136
+ class Program
137
+ {
138
+ static void Main (string [] args )
139
+ {
140
+ TelemetryConfiguration configuration = TelemetryConfiguration .Active ;
131
141
132
- configuration .InstrumentationKey = " removed" ;
133
- configuration .TelemetryInitializers .Add (new OperationCorrelationTelemetryInitializer ());
134
- configuration .TelemetryInitializers .Add (new HttpDependenciesParsingTelemetryInitializer ());
142
+ configuration .InstrumentationKey = " removed" ;
143
+ configuration .TelemetryInitializers .Add (new OperationCorrelationTelemetryInitializer ());
144
+ configuration .TelemetryInitializers .Add (new HttpDependenciesParsingTelemetryInitializer ());
135
145
136
- var telemetryClient = new TelemetryClient ();
137
- using (InitializeDependencyTracking (configuration ))
138
- {
139
- // run app...
140
-
141
- telemetryClient .TrackTrace (" Hello World!" );
146
+ var telemetryClient = new TelemetryClient ();
147
+ using (InitializeDependencyTracking (configuration ))
148
+ {
149
+ // run app...
150
+
151
+ telemetryClient .TrackTrace (" Hello World!" );
152
+
153
+ using (var httpClient = new HttpClient ())
154
+ {
155
+ // Http dependency is automatically tracked!
156
+ httpClient .GetAsync (" https://microsoft.com" ).Wait ();
157
+ }
158
+
159
+ }
160
+
161
+ // before exit, flush the remaining data
162
+ telemetryClient .Flush ();
163
+
164
+ // flush is not blocking so wait a bit
165
+ Task .Delay (5000 ).Wait ();
142
166
143
- using (var httpClient = new HttpClient ())
144
- {
145
- // Http dependency is automatically tracked!
146
- httpClient .GetAsync (" https://microsoft.com" ).Wait ();
147
167
}
148
168
149
- }
169
+ static DependencyTrackingTelemetryModule InitializeDependencyTracking (TelemetryConfiguration configuration )
170
+ {
171
+ var module = new DependencyTrackingTelemetryModule ();
150
172
151
- // before exit, flush the remaining data
152
- telemetryClient .Flush ();
153
-
154
- // flush is not blocking so wait a bit
155
- Task .Delay (5000 ).Wait ();
173
+ // prevent Correlation Id to be sent to certain endpoints. You may add other domains as needed.
174
+ module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.windows.net" );
175
+ module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.chinacloudapi.cn" );
176
+ module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.cloudapi.de" );
177
+ module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.usgovcloudapi.net" );
178
+ module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" localhost" );
179
+ module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" 127.0.0.1" );
156
180
157
- }
181
+ // enable known dependency tracking, note that in future versions, we will extend this list.
182
+ // please check default settings in https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/DependencyCollector/NuGet/ApplicationInsights.config.install.xdt#L20
183
+ module .IncludeDiagnosticSourceActivities .Add (" Microsoft.Azure.ServiceBus" );
184
+ module .IncludeDiagnosticSourceActivities .Add (" Microsoft.Azure.EventHubs" );
158
185
159
- static DependencyTrackingTelemetryModule InitializeDependencyTracking (TelemetryConfiguration configuration )
160
- {
161
- var module = new DependencyTrackingTelemetryModule ();
162
-
163
- // prevent Correlation Id to be sent to certain endpoints. You may add other domains as needed.
164
- module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.windows.net" );
165
- module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.chinacloudapi.cn" );
166
- module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.cloudapi.de" );
167
- module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" core.usgovcloudapi.net" );
168
- module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" localhost" );
169
- module .ExcludeComponentCorrelationHttpHeadersOnDomains .Add (" 127.0.0.1" );
170
-
171
- // enable known dependency tracking, note that in future versions, we will extend this list.
172
- // please check default settings in https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/develop/Src/DependencyCollector/NuGet/ApplicationInsights.config.install.xdt#L20
173
- module .IncludeDiagnosticSourceActivities .Add (" Microsoft.Azure.ServiceBus" );
174
- module .IncludeDiagnosticSourceActivities .Add (" Microsoft.Azure.EventHubs" );
175
-
176
- // initialize the module
177
- module .Initialize (configuration );
178
-
179
- return module ;
186
+ // initialize the module
187
+ module .Initialize (configuration );
188
+
189
+ return module ;
190
+ }
191
+ }
180
192
}
193
+
181
194
```
182
195
183
196
## Next steps
0 commit comments