Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable zipkin endpoint configuration via environment variable #1924

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
28a9d47
enable ipking enpoint config via env variable
vishweshbankwar Mar 19, 2021
e97cbe4
update changelog
vishweshbankwar Mar 19, 2021
2f16f16
fix md error
vishweshbankwar Mar 19, 2021
27b35ee
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Mar 19, 2021
d1f58fb
Trigger build
vishweshbankwar Mar 19, 2021
8b335f6
Adding test
vishweshbankwar Mar 22, 2021
dd1b45f
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Mar 26, 2021
7077fcc
Added more test and updated readme
vishweshbankwar Mar 26, 2021
f370f5f
updating readme
vishweshbankwar Mar 30, 2021
5b1c6fd
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Mar 30, 2021
ec80f35
updates to zipkin readme
vishweshbankwar Mar 31, 2021
010bf58
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Mar 31, 2021
f2d0284
resolving PR comments
vishweshbankwar Apr 2, 2021
a0941f4
Merge branch 'vibankwa/Enable-Zipkin-Endpoint-Configuration-via-Env-V…
vishweshbankwar Apr 2, 2021
31fea42
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Apr 2, 2021
053d335
moved endpoint init to ctor with try catch
vishweshbankwar Apr 13, 2021
13cee05
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Apr 13, 2021
6bcf977
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar May 25, 2021
a800ae9
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Jun 23, 2021
ce391ef
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Jul 10, 2021
827e518
resolving PR comments
vishweshbankwar Jul 10, 2021
cf830b3
Minor change
vishweshbankwar Jul 12, 2021
f345254
resolve PR comments
vishweshbankwar Jul 15, 2021
30f3c0c
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Jul 15, 2021
bc32815
Merge branch 'main' into vibankwa/Enable-Zipkin-Endpoint-Configuratio…
vishweshbankwar Jul 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Enabling endpoint configuration in ZipkinExporterOptions via
`OTEL_EXPORTER_ZIPKIN_ENDPOINT` environment variable.
([#1453](https://github.com/open-telemetry/opentelemetry-dotnet/issues/1453))

## 1.1.0-rc1

Released 2021-Jun-25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,25 @@ public void FailedExport(Exception ex)
}
}

[NonEvent]
public void FailedEndpointInitialization(Exception ex)
{
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1)))
{
this.FailedEndpointInitialization(ex.ToInvariantString());
}
}

[Event(1, Message = "Failed to export activities: '{0}'", Level = EventLevel.Error)]
public void FailedExport(string exception)
{
this.WriteEvent(1, exception);
}

[Event(2, Message = "Error initializing Zipkin endpoint, falling back to default value: '{0}'", Level = EventLevel.Error)]
public void FailedEndpointInitialization(string exception)
{
this.WriteEvent(2, exception);
}
}
}
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Exporter.Zipkin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ You can configure the `ZipkinExporter` through
associated with the telemetry has "service.name" defined, then it'll be
preferred over this option.
* `Endpoint`: URI address to receive telemetry (default `http://localhost:9411/api/v2/spans`).
reyang marked this conversation as resolved.
Show resolved Hide resolved

The endpoint configuration can be provided either [via code](../../examples/Console/TestZipkinExporter.cs)
or
[via environment variable](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#zipkin-exporter),
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
with code taking precedence over environment variable.

* `UseShortTraceIds`: Whether the trace's ID should be shortened before
sending to Zipkin (default false).
* `MaxPayloadSizeInBytes`: Maximum payload size - for .NET versions
Expand Down
22 changes: 21 additions & 1 deletion src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Diagnostics;
using OpenTelemetry.Exporter.Zipkin.Implementation;

namespace OpenTelemetry.Exporter
{
Expand All @@ -27,12 +28,31 @@ public sealed class ZipkinExporterOptions
#if !NET452
internal const int DefaultMaxPayloadSizeInBytes = 4096;
#endif
internal const string ZipkinEndpointEnvVar = "OTEL_EXPORTER_ZIPKIN_ENDPOINT";
internal const string DefaultZipkinEndpoint = "http://localhost:9411/api/v2/spans";

/// <summary>
/// Initializes a new instance of the <see cref="ZipkinExporterOptions"/> class.
/// Initializes zipkin endpoint.
/// </summary>
public ZipkinExporterOptions()
{
try
{
this.Endpoint = new Uri(Environment.GetEnvironmentVariable(ZipkinEndpointEnvVar) ?? DefaultZipkinEndpoint);
}
catch (Exception ex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor (may follow up in separate PR):
We can do similar to what Jaeger/OTLP does - catch SecurityException for reading env variable. Handle the Uri parse exception separately. Both should be logged as separate EventSource events.
This avoids catching the generic Exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - will create a separate PR for that.

{
this.Endpoint = new Uri(DefaultZipkinEndpoint);
ZipkinExporterEventSource.Log.FailedEndpointInitialization(ex);
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// <summary>
/// Gets or sets Zipkin endpoint address. See https://zipkin.io/zipkin-api/#/default/post_spans.
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
/// Typically https://zipkin-server-name:9411/api/v2/spans.
/// </summary>
public Uri Endpoint { get; set; } = new Uri("http://localhost:9411/api/v2/spans");
public Uri Endpoint { get; set; }

/// <summary>
/// Gets or sets a value indicating whether short trace id should be used.
Expand Down
54 changes: 54 additions & 0 deletions test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,60 @@ public void SuppresssesInstrumentation()
Assert.Equal(1, endCalledCount);
}

[Fact]
public void EndpointConfigurationUsingEnvironmentVariable()
{
try
{
Environment.SetEnvironmentVariable(ZipkinExporterOptions.ZipkinEndpointEnvVar, "http://urifromenvironmentvariable");

var exporterOptions = new ZipkinExporterOptions();

Assert.Equal(new Uri(Environment.GetEnvironmentVariable(ZipkinExporterOptions.ZipkinEndpointEnvVar)).AbsoluteUri, exporterOptions.Endpoint.AbsoluteUri);
}
finally
{
Environment.SetEnvironmentVariable(ZipkinExporterOptions.ZipkinEndpointEnvVar, null);
}
}

[Fact]
public void IncodeEndpointConfigTakesPrecedenceOverEnvironmentVariable()
{
try
{
Environment.SetEnvironmentVariable(ZipkinExporterOptions.ZipkinEndpointEnvVar, "http://urifromenvironmentvariable");

var exporterOptions = new ZipkinExporterOptions
{
Endpoint = new Uri("http://urifromcode"),
};

Assert.Equal(new Uri("http://urifromcode").AbsoluteUri, exporterOptions.Endpoint.AbsoluteUri);
}
finally
{
Environment.SetEnvironmentVariable(ZipkinExporterOptions.ZipkinEndpointEnvVar, null);
}
}

[Fact]
public void ErrorGettingUriFromEnvVarSetsDefaultEndpointValue()
{
try
{
Environment.SetEnvironmentVariable(ZipkinExporterOptions.ZipkinEndpointEnvVar, "InvalidUri");

var exporterOptions = new ZipkinExporterOptions();

Assert.Equal(new Uri(ZipkinExporterOptions.DefaultZipkinEndpoint).AbsoluteUri, exporterOptions.Endpoint.AbsoluteUri);
}
finally
{
Environment.SetEnvironmentVariable(ZipkinExporterOptions.ZipkinEndpointEnvVar, null);
}
}
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved

[Theory]
[InlineData(true, false, false)]
[InlineData(false, false, false)]
Expand Down