Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit c93b396

Browse files
More clean up (#38)
* added samples * fix urls * link to sample * few more warnings * addressed PR feedback * speed up build
1 parent 5dac82f commit c93b396

Some content is hidden

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

54 files changed

+378
-186
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22

3+
- Initial version of Application Insights exporter implemented.
34
- Zipkin exporter implemented.
45
- Initial version of SDK published. It is based on contribution from Pivotal
56
[from](https://github.com/SteeltoeOSS/Management/tree/dev/src/Steeltoe.Management.OpenCensus).

OpenCensus.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".vsts", ".vsts", "{61188153
3636
EndProject
3737
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCensus.Exporter.ApplicationInsights", "src\OpenCensus.Exporter.ApplicationInsights\OpenCensus.Exporter.ApplicationInsights.csproj", "{4493F5D9-874E-4FBF-B2F3-37890BD910E0}"
3838
EndProject
39+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "src\Samples\Samples.csproj", "{C58393EB-32E2-4AC6-9170-697B36306E15}"
40+
EndProject
3941
Global
4042
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4143
Debug|Any CPU = Debug|Any CPU
@@ -58,6 +60,10 @@ Global
5860
{4493F5D9-874E-4FBF-B2F3-37890BD910E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
5961
{4493F5D9-874E-4FBF-B2F3-37890BD910E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
6062
{4493F5D9-874E-4FBF-B2F3-37890BD910E0}.Release|Any CPU.Build.0 = Release|Any CPU
63+
{C58393EB-32E2-4AC6-9170-697B36306E15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
64+
{C58393EB-32E2-4AC6-9170-697B36306E15}.Debug|Any CPU.Build.0 = Debug|Any CPU
65+
{C58393EB-32E2-4AC6-9170-697B36306E15}.Release|Any CPU.ActiveCfg = Release|Any CPU
66+
{C58393EB-32E2-4AC6-9170-697B36306E15}.Release|Any CPU.Build.0 = Release|Any CPU
6167
EndGlobalSection
6268
GlobalSection(SolutionProperties) = preSolution
6369
HideSolutionNode = FALSE

README.md

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# OpenCensus .NET SDK - distributed tracing and stats collection framework
22

33
[![Gitter chat][gitter-image]][gitter-url]
4+
[![Build Status](https://opencensus.visualstudio.com/continuous-integration/_apis/build/status/ci-myget-update.yml)](https://opencensus.visualstudio.com/continuous-integration/_build/latest?definitionId=3)
5+
6+
| Source | OpenCensus | Zipkin Exporter | Application Insights exporter |
7+
|--------|------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
8+
| MyGet | [![MyGet Nightly][opencensus-myget-image]][opencensus-myget-url] | [![MyGet Nightly][opencensus-exporter-zipkin-myget-image]][opencensus-exporter-zipkin-myget-url] | [![MyGet Nightly][opencensus-exporter-ai-myget-image]][opencensus-exporter-ai-myget-url] |
49

5-
MyGet: [![MyGet Nightly][opencensus-myget-image]][opencensus-myget-url]
610

711
OpenCensus is a toolkit for collecting application performance and behavior
812
data. It currently includes 3 APIs: stats, tracing and tags.
@@ -14,37 +18,56 @@ major release.
1418
Please join [gitter](https://gitter.im/census-instrumentation/Lobby) for help
1519
or feedback on this project.
1620

17-
We encourage contributions. Use tags
18-
[up-for-grabs](https://github.com/census-instrumentation/opencensus-csharp/issues?q=is%3Aissue+is%3Aopen+label%3Aup-for-grabs)
19-
and [good first
20-
issue](https://github.com/census-instrumentation/opencensus-csharp/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
21-
to get started with the project. Follow [CONTRIBUTING](CONTRIBUTING.md) guide
22-
to report issues or submit a proposal.
21+
We encourage contributions. Use tags [up-for-grabs][up-for-grabs-issues] and
22+
[good first issue][good-first-issues] to get started with the project. Follow
23+
[CONTRIBUTING](CONTRIBUTING.md) guide to report issues or submit a proposal.
2324

2425
## OpenCensus Quickstart
2526

2627
### Using Zipkin exporter
2728

2829
Configure Zipkin exporter to see traces in Zipkin UI.
2930

30-
1. Get Zipkin using getting [started
31-
guide](https://zipkin.io/pages/quickstart.html).
31+
1. Get Zipkin using [getting started guide][zipkin-get-started].
3232
2. Start `ZipkinTraceExporter` as below:
33+
3. See [sample][zipkin-sample] for example use.
3334

3435
``` csharp
3536
var exporter = new ZipkinTraceExporter(
3637
new ZipkinTraceExporterOptions() {
37-
Endpoint = "https://<zipkin-server:9411>/api/v2/spans",
38+
Endpoint = new Uri("https://<zipkin-server:9411>/api/v2/spans"),
3839
ServiceName = typeof(Program).Assembly.GetName().Name,
3940
},
4041
Tracing.ExportComponent);
4142
exporter.Start();
4243

43-
var span = tracer.SpanBuilder("incoming request").SetSampler(Samplers.AlwaysSample).StartSpan();
44+
var span = tracer
45+
.SpanBuilder("incoming request")
46+
.SetSampler(Samplers.AlwaysSample)
47+
.StartSpan();
48+
4449
Thread.Sleep(TimeSpan.FromSeconds(1));
4550
span.End();
4651
```
4752

53+
### Using Application Insights exporter
54+
55+
1. Create [Application Insights][ai-get-started] resource.
56+
2. Set instrumentation key via telemetry configuration object
57+
(`new TelemetryConfiguration("iKey")`). This object may be injected via
58+
dependency injection as well.
59+
3. Instantiate a new instance of `ApplicationInsightsExporter`.
60+
4. See [sample][ai-sample] for example use.
61+
62+
``` csharp
63+
var config = new TelemetryConfiguration("iKey")
64+
var exporter = new ApplicationInsightsExporter(
65+
Tracing.ExportComponent,
66+
Stats.ViewManager,
67+
config); // either global or local config can be used
68+
exporter.Start();
69+
```
70+
4871
## Versioning
4972

5073
This library follows [Semantic Versioning][semver].
@@ -64,10 +87,17 @@ opencensus libraries, then there is no deprecation period. Otherwise, we will
6487
deprecate it for 18 months before removing it, if possible.
6588

6689
[gitter-image]: https://badges.gitter.im/census-instrumentation/lobby.svg
67-
[gitter-url]:
68-
https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
69-
[opencensus-myget-image]:
70-
https://img.shields.io/myget/opencensus/vpre/OpenCensus.svg
71-
[opencensus-myget-url]:
72-
https://www.myget.org/feed/opencensus/package/nuget/OpenCensus [semver]:
73-
http://semver.org/
90+
[gitter-url]:https://gitter.im/census-instrumentation/lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
91+
[opencensus-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.svg
92+
[opencensus-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus
93+
[opencensus-exporter-zipkin-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Exporter.Zipkin.svg
94+
[opencensus-exporter-zipkin-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Exporter.Zipkin
95+
[opencensus-exporter-ai-myget-image]:https://img.shields.io/myget/opencensus/vpre/OpenCensus.Exporter.ApplicationInsights.svg
96+
[opencensus-exporter-ai-myget-url]: https://www.myget.org/feed/opencensus/package/nuget/OpenCensus.Exporter.ApplicationInsights
97+
[up-for-grabs-issues]: https://github.com/census-instrumentation/opencensus-csharp/issues?q=is%3Aissue+is%3Aopen+label%3Aup-for-grabs
98+
[good-first-issues]: https://github.com/census-instrumentation/opencensus-csharp/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22
99+
[zipkin-get-started]: https://zipkin.io/pages/quickstart.html
100+
[ai-get-started]: https://docs.microsoft.com/azure/application-insights
101+
[semver]: http://semver.org/
102+
[ai-sample]: https://github.com/census-instrumentation/opencensus-csharp/blob/develop/src/Samples/TestApplicationInsights.cs
103+
[zipkin-sample]: https://github.com/census-instrumentation/opencensus-csharp/blob/develop/src/Samples/TestZipkin.cs

src/OpenCensus.Exporter.ApplicationInsights/ApplicationInsightsExporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public class ApplicationInsightsExporter
4848
/// <summary>
4949
/// Instantiates a new instance of an exporter from Open Census to Azure Application Insights.
5050
/// </summary>
51-
/// <param name="telemetryConfiguration">Telemetry configuration to use to report telemetry.</param>
5251
/// <param name="exportComponent">Exporter to get traces and metrics from.</param>
5352
/// <param name="viewManager">View manager to get stats from.</param>
54-
public ApplicationInsightsExporter(TelemetryConfiguration telemetryConfiguration, IExportComponent exportComponent, IViewManager viewManager)
53+
/// <param name="telemetryConfiguration">Telemetry configuration to use to report telemetry.</param>
54+
public ApplicationInsightsExporter(IExportComponent exportComponent, IViewManager viewManager, TelemetryConfiguration telemetryConfiguration)
5555
{
5656
this.exportComponent = exportComponent;
5757
this.viewManager = viewManager;

src/OpenCensus.Exporter.ApplicationInsights/Implementation/MetricsExporterThread.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal void Export()
8787
{
8888
var metricTelemetry = new MetricTelemetry
8989
{
90-
Name = data.View.Name.AsString
90+
Name = data.View.Name.AsString,
9191
};
9292

9393
for (int i = 0; i < value.Key.Values.Count; i++)
@@ -115,6 +115,7 @@ internal void Export()
115115
{
116116
metricTelemetry.Sum = sum.Sum;
117117
}
118+
118119
return null;
119120
},
120121
(combined) =>
@@ -123,6 +124,7 @@ internal void Export()
123124
{
124125
metricTelemetry.Sum = sum.Sum;
125126
}
127+
126128
return null;
127129
},
128130
(combined) =>
@@ -131,13 +133,15 @@ internal void Export()
131133
{
132134
metricTelemetry.Sum = count.Count;
133135
}
136+
134137
return null;
135138
},
136139
(combined) =>
137140
{
138141
if (combined is IMeanData mean)
139142
{
140143
}
144+
141145
return null;
142146
},
143147
(combined) =>
@@ -158,6 +162,7 @@ internal void Export()
158162
{
159163
metricTelemetry.Sum = lastValue.LastValue;
160164
}
165+
161166
return null;
162167
},
163168
(combined) =>
@@ -166,6 +171,7 @@ internal void Export()
166171
{
167172
metricTelemetry.Sum = lastValue.LastValue;
168173
}
174+
169175
return null;
170176
},
171177
(combined) =>
@@ -174,6 +180,7 @@ internal void Export()
174180
{
175181
// TODO: report an error
176182
}
183+
177184
return null;
178185
});
179186
this.telemetryClient.TrackMetric(metricTelemetry);
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenCensus.sln'))\build\Common.prod.props" />
23

34
<PropertyGroup>
45
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
56
<TargetFrameworks Condition="$(OS) != 'Windows_NT'">netstandard2.0</TargetFrameworks>
7+
<IncludeSymbols>True</IncludeSymbols>
68
</PropertyGroup>
79

810
<PropertyGroup>
9-
<CodeAnalysisRuleSet>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenCensus.sln'))\build\OpenCensus.prod.ruleset</CodeAnalysisRuleSet>
10-
</PropertyGroup>
11-
12-
<PropertyGroup>
13-
<DocumentationFile Condition="$(OS) == 'Windows_NT'">$(OutputPath)/$(TargetFramework)/$(AssemblyName).xml</DocumentationFile>
14-
</PropertyGroup>
15-
16-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net46|AnyCPU'">
17-
<PlatformTarget>x64</PlatformTarget>
11+
<Description>Application Insights exporter for Open Census.</Description>
12+
<PackageTags>Tracing;OpenCensus;Management;Monitoring;application-insights;azure;distributed-tracing</PackageTags>
13+
<PackageIconUrl>https://opencensus.io/images/opencensus-logo.png</PackageIconUrl>
14+
<PackageProjectUrl>https://opencensus.io</PackageProjectUrl>
15+
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
16+
<Authors>OpenCensus authors</Authors>
17+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1818
</PropertyGroup>
1919

2020
<ItemGroup>
2121
<AdditionalFiles Include="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenCensus.sln'))\build\stylecop.json" />
2222
</ItemGroup>
2323

24-
2524
<ItemGroup>
2625
<ProjectReference Include="..\OpenCensus\OpenCensus.csproj" />
27-
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
26+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008">
2827
<PrivateAssets>All</PrivateAssets>
2928
</PackageReference>
3029
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.8.0-beta1" />
3130
</ItemGroup>
32-
3331
</Project>

src/OpenCensus.Exporter.Zipkin/Implementation/TraceExporterHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private async void SendSpansAsync(List<ZipkinSpan> spans)
216216
{
217217
try
218218
{
219-
var requestUri = new Uri(this.options.Endpoint);
219+
var requestUri = this.options.Endpoint;
220220
var request = this.GetHttpRequestMessage(HttpMethod.Post, requestUri);
221221
request.Content = this.GetRequestContent(spans);
222222
await this.DoPost(this.httpClient, request);

src/OpenCensus.Exporter.Zipkin/OpenCensus.Exporter.Zipkin.csproj

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'OpenCensus.sln'))\build\Common.prod.props" />
33

44
<PropertyGroup>
5-
<Description>OpenCensus .NET API</Description>
65
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
76
<TargetFrameworks Condition="$(OS) != 'Windows_NT'">netstandard2.0</TargetFrameworks>
8-
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
9-
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
10-
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
11-
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
127
<IncludeSymbols>True</IncludeSymbols>
13-
<PackageId>OpenCensus.Export.Zipkin</PackageId>
14-
<PackageTags>Tracing;OpenCensus;Management;Monitoring;Zipkin</PackageTags>
8+
</PropertyGroup>
9+
10+
<PropertyGroup>
11+
<Description>Zipkin exporter for OpenCensus</Description>
12+
<PackageTags>Tracing;OpenCensus;Management;Monitoring;Zipkin;distributed-tracing</PackageTags>
1513
<PackageIconUrl>https://opencensus.io/images/opencensus-logo.png</PackageIconUrl>
1614
<PackageProjectUrl>https://opencensus.io</PackageProjectUrl>
1715
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
@@ -27,9 +25,7 @@
2725
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
2826
</ItemGroup>
2927

30-
3128
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
3229
<Reference Include="System.Net.Http" />
3330
</ItemGroup>
34-
3531
</Project>

src/OpenCensus.Exporter.Zipkin/ZipkinTraceExporterOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public sealed class ZipkinTraceExporterOptions
2727
/// Gets or sets Zipkin endpoint address. See https://zipkin.io/zipkin-api/#/default/post_spans.
2828
/// Typically https://zipkin-server-name:9411/api/v2/spans.
2929
/// </summary>
30-
public string Endpoint { get; set; } = "http://localhost:9411/api/v2/spans";
30+
public Uri Endpoint { get; set; } = new Uri("http://localhost:9411/api/v2/spans");
3131

3232
/// <summary>
3333
/// Gets or sets timeout in seconds.

src/OpenCensus/Api/Stats/IAggregation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace OpenCensus.Stats
2121

2222
public interface IAggregation
2323
{
24-
M Match<M>(
25-
Func<ISum, M> p0,
26-
Func<ICount, M> p1,
27-
Func<IMean, M> p2,
28-
Func<IDistribution, M> p3,
29-
Func<ILastValue, M> p4,
30-
Func<IAggregation, M> p6);
24+
T Match<T>(
25+
Func<ISum, T> p0,
26+
Func<ICount, T> p1,
27+
Func<IMean, T> p2,
28+
Func<IDistribution, T> p3,
29+
Func<ILastValue, T> p4,
30+
Func<IAggregation, T> p6);
3131
}
3232
}

0 commit comments

Comments
 (0)