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

Commit 44a038c

Browse files
Simon ZeltserSergeyKanzhelev
authored andcommitted
Added command line support for samples project for convenient testing (#54)
* Introducing Stackdriver Exporter for Opencensus C# library - Current implementation can only store string values - Added the exporter and trace handler only - The exporter relies on newest Trace API from Stackdriver. * Updating translation from ISpan to Stackdriver's Span to cover more fields * Fixing the issue that prevented Stackdriver API call to succeed: now construction of Span resource is taken care of by SpanName class that is part of Stackdriver Trace V2 API. * - Added support for capturing all types of trace spans (long/bool/string) - Fixed csproj, so it produces both .NET Core and .NET versions. It also means signing the assembly using the same mechanism as other assemblies in the solution * - Added support for storing links - Minor fixes to proto<->opencensus translation methods * Fixing merge issue * Added command line support for the Samples project. This will make it easier to script testing multiple exporters as well as prevent commenting and uncommenting different test procedures for different exporters. Finally, it will making test code cleaner for showing samples embedded in documentation website. In order to test the exporter, you can either execute it from the command line: samples.dll prometheus or to debug using Visual Studio: Debug => Sample Properties => Debug. Now create a profile for your testing execution and fill application arguments if needed. Now choose your profile in running configuration of Visual Studio. Running settings are local to the machine and are ignored in PRs.
1 parent 9eafe7a commit 44a038c

File tree

10 files changed

+76
-14
lines changed

10 files changed

+76
-14
lines changed

src/OpenCensus.Collector.AspNetCore/RequestsCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class RequestsCollector : IDisposable
3535
/// </summary>
3636
/// <param name="options">Configuration options for dependencies collector.</param>
3737
/// <param name="tracer">Tracer to record traced with.</param>
38-
/// <param name="sampler">Sampler to use to sample dependnecy calls.</param>
38+
/// <param name="sampler">Sampler to use to sample dependency calls.</param>
3939
/// <param name="propagationComponent">Wire context propagation component.</param>
4040
public RequestsCollector(RequestsCollectorOptions options, ITracer tracer, ISampler sampler, IPropagationComponent propagationComponent)
4141
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal void Export()
9797
metricTelemetry.Properties.Add(name, val);
9898
}
9999

100-
// Now those propertis needs to be populated.
100+
// Now those properties needs to be populated.
101101
//
102102
// metricTelemetry.Sum
103103
// metricTelemetry.Count

src/OpenCensus.Exporter.Stackdriver/StackdriverExporter.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace OpenCensus.Exporter.Stackdriver
2020
using OpenCensus.Exporter.Stackdriver.Implementation;
2121
using OpenCensus.Trace.Export;
2222

23+
/// <summary>
24+
/// Implementation of the exporter to Stackdriver
25+
/// </summary>
2326
public class StackdriverExporter
2427
{
2528
private const string ExporterName = "StackdriverTraceExporter";
@@ -35,6 +38,9 @@ public StackdriverExporter(string projectId, IExportComponent exportComponent)
3538
this.exportComponent = exportComponent;
3639
}
3740

41+
/// <summary>
42+
/// Starts the exporter
43+
/// </summary>
3844
public void Start()
3945
{
4046
lock (locker)
@@ -46,11 +52,14 @@ public void Start()
4652

4753
var traceExporter = new StackdriverTraceExporter(projectId);
4854
exportComponent.SpanExporter.RegisterHandler(ExporterName, traceExporter);
49-
55+
5056
isInitialized = true;
5157
}
5258
}
5359

60+
/// <summary>
61+
/// Stops the exporter
62+
/// </summary>
5463
public void Stop()
5564
{
5665
lock (locker)

src/Samples/Program.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,61 @@
11
namespace Samples
22
{
3+
using CommandLine;
34
using System;
45

6+
[Verb("stackdriver", HelpText = "Specify the options required to test Stackdriver exporter", Hidden = false)]
7+
class StackdriverOptions
8+
{
9+
[Option('p', "projectId", HelpText = "Please specify the projectId of your GCP project", Required = true)]
10+
public string ProjectId { get; set; }
11+
}
12+
13+
[Verb("zipkin", HelpText = "Specify the options required to test Zipkin exporter")]
14+
class ZipkinOptions
15+
{
16+
}
17+
18+
[Verb("appInsights", HelpText = "Specify the options required to test ApplicationInsights")]
19+
class ApplicationInsightsOptions
20+
{
21+
}
22+
23+
[Verb("prometheus", HelpText = "Specify the options required to test Prometheus")]
24+
class PrometheusOptions
25+
{
26+
}
27+
28+
[Verb("httpclient", HelpText = "Specify the options required to test HttpClient")]
29+
class HttpClientOptions
30+
{
31+
}
32+
533
/// <summary>
634
/// Main samples entry point.
735
/// </summary>
836
public class Program
937
{
1038
/// <summary>
11-
/// Main method.
39+
/// Main method - invoke this using command line.
40+
/// For example:
41+
///
42+
/// Samples.dll zipkin
43+
/// Sample.dll appInsights
44+
/// Sample.dll prometheus
1245
/// </summary>
1346
/// <param name="args">Arguments from command line.</param>
1447
public static void Main(string[] args)
1548
{
16-
Console.WriteLine("Uncomment test to run... ");
17-
18-
TestZipkin.Run();
49+
Parser.Default.ParseArguments<ZipkinOptions, ApplicationInsightsOptions, PrometheusOptions, HttpClientOptions, StackdriverOptions>(args)
50+
.MapResult(
51+
(ZipkinOptions options) => TestZipkin.Run(),
52+
(ApplicationInsightsOptions options) => TestApplicationInsights.Run(),
53+
(PrometheusOptions options) => TestPrometheus.Run(),
54+
(HttpClientOptions options) => TestHttpClient.Run(),
55+
(StackdriverOptions options) => TestStackdriver.Run(options.ProjectId),
56+
errs => 1);
57+
58+
// TestZipkin.Run();
1959
// TestApplicationInsights.Run();
2060
// TestPrometheus.Run();
2161
// TestHttpClient.Run();

src/Samples/Samples.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<TargetFramework>netcoreapp2.0</TargetFramework>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<PackageReference Include="CommandLineParser" Version="2.3.0" />
10+
</ItemGroup>
11+
812
<ItemGroup>
913
<ProjectReference Include="..\OpenCensus.Collector.Dependencies\OpenCensus.Collector.Dependencies.csproj" />
1014
<ProjectReference Include="..\OpenCensus.Exporter.Stackdriver\OpenCensus.Exporter.Stackdriver.csproj" />

src/Samples/TestApplicationInsights.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal class TestApplicationInsights
3232
Distribution.Create(BucketBoundaries.Create(new List<double>() { 0.0, 16.0 * MiB, 256.0 * MiB })),
3333
new List<ITagKey>() { FrontendKey });
3434

35-
internal static void Run()
35+
internal static object Run()
3636
{
3737
TelemetryConfiguration.Active.InstrumentationKey = "instrumentation-key";
3838
var exporter = new ApplicationInsightsExporter(Tracing.ExportComponent, Stats.ViewManager, TelemetryConfiguration.Active);
@@ -66,6 +66,8 @@ internal static void Run()
6666

6767
Console.WriteLine("Done... wait for events to arrive to backend!");
6868
Console.ReadLine();
69+
70+
return null;
6971
}
7072
}
7173
}

src/Samples/TestHttpClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class TestHttpClient
1212
{
1313
private static ITracer tracer = Tracing.Tracer;
1414

15-
internal static void Run()
15+
internal static object Run()
1616
{
1717
Console.WriteLine("Hello World!");
1818

@@ -38,6 +38,8 @@ internal static void Run()
3838
scope.Dispose();
3939

4040
Console.ReadLine();
41+
42+
return null;
4143
}
4244
}
4345
}

src/Samples/TestPrometheus.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class TestPrometheus
3131
Distribution.Create(BucketBoundaries.Create(new List<double>() { 0.0, 16.0 * MiB, 256.0 * MiB })),
3232
new List<ITagKey>() { FrontendKey });
3333

34-
internal static void Run()
34+
internal static object Run()
3535
{
3636
var exporter = new PrometheusExporter(
3737
new PrometheusExporterOptions()
@@ -72,6 +72,8 @@ internal static void Run()
7272
{
7373
exporter.Stop();
7474
}
75+
76+
return null;
7577
}
7678
}
7779
}

src/Samples/TestStackdriver.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ internal class TestStackdriver
3131
Distribution.Create(BucketBoundaries.Create(new List<double>() { 0.0, 16.0 * MiB, 256.0 * MiB })),
3232
new List<ITagKey>() { FrontendKey });
3333

34-
internal static void Run()
34+
internal static object Run(string projectId)
3535
{
36-
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"C:\Users\zeltser\Downloads\aspnetcoreissue-1af8a0ca869b.json");
37-
var exporter = new StackdriverExporter("aspnetcoreissue", Tracing.ExportComponent);
36+
var exporter = new StackdriverExporter(projectId, Tracing.ExportComponent);
3837
exporter.Start();
3938

4039
ITagContextBuilder tagContextBuilder = tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5"));
@@ -65,6 +64,8 @@ internal static void Run()
6564

6665
Console.WriteLine("Done... wait for events to arrive to backend!");
6766
Console.ReadLine();
67+
68+
return null;
6869
}
6970
}
7071
}

src/Samples/TestZipkin.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal class TestZipkin
1010
{
1111
private static ITracer tracer = Tracing.Tracer;
1212

13-
internal static void Run()
13+
internal static object Run()
1414
{
1515
Console.WriteLine("Hello World!");
1616

@@ -30,6 +30,8 @@ internal static void Run()
3030
span2.End();
3131

3232
Console.ReadLine();
33+
34+
return null;
3335
}
3436
}
3537
}

0 commit comments

Comments
 (0)