Skip to content

Commit

Permalink
Merge branch 'main' into cijothomas/loggerformatternullcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Jul 29, 2021
2 parents 7cb48d6 + 138035b commit 5b4b8cb
Show file tree
Hide file tree
Showing 15 changed files with 618 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this IMetric metric)
var otlpMetric = new OtlpMetrics.Metric
{
Name = metric.Name,
Description = metric.Description,
Unit = metric.Unit,
};

if (metric.Description != null)
{
otlpMetric.Description = metric.Description;
}

if (metric.Unit != null)
{
otlpMetric.Unit = metric.Unit;
}

if (metric is ISumMetric sumMetric)
{
var sum = new OtlpMetrics.Sum
Expand All @@ -133,7 +141,7 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this IMetric metric)
? OtlpMetrics.AggregationTemporality.Delta
: OtlpMetrics.AggregationTemporality.Cumulative,
};
var dataPoint = metric.ToNumberDataPoint(sumMetric.Sum, sumMetric.Exemplars);
var dataPoint = metric.ToNumberDataPoint(sumMetric.Sum.Value, sumMetric.Exemplars);
sum.DataPoints.Add(dataPoint);
otlpMetric.Sum = sum;
}
Expand Down Expand Up @@ -238,7 +246,7 @@ private static OtlpMetrics.NumberDataPoint ToNumberDataPoint(this IMetric metric
{
// TODO: Determine how we want to handle exceptions here.
// Do we want to just skip this metric and move on?
throw new ArgumentException();
throw new ArgumentException($"Value must be a long or a double.", nameof(value));
}

// TODO: Do TagEnumerationState thing.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <copyright file="MetricsService.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Threading;
using Grpc.Core;

namespace Opentelemetry.Proto.Collector.Metrics.V1
{
/// <summary>
/// MetricsService extensions.
/// </summary>
internal static partial class MetricsService
{
/// <summary>Interface for MetricService.</summary>
public interface IMetricsServiceClient
{
/// <summary>
/// For performance reasons, it is recommended to keep this RPC
/// alive for the entire life of the application.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
/// <param name="cancellationToken">An optional token for canceling the call.</param>
/// <returns>The response received from the server.</returns>
ExportMetricsServiceResponse Export(ExportMetricsServiceRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default);
}

/// <summary>
/// MetricServiceClient extensions.
/// </summary>
public partial class MetricsServiceClient : IMetricsServiceClient
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class OtlpMetricsExporter : BaseExporter<MetricItem>
#else
private readonly Channel channel;
#endif
private readonly OtlpCollector.MetricsService.MetricsServiceClient metricsClient;
private readonly OtlpCollector.MetricsService.IMetricsServiceClient metricsClient;
private readonly Metadata headers;

/// <summary>
Expand All @@ -59,8 +59,8 @@ public OtlpMetricsExporter(OtlpExporterOptions options)
/// Initializes a new instance of the <see cref="OtlpMetricsExporter"/> class.
/// </summary>
/// <param name="options">Configuration options for the exporter.</param>
/// <param name="metricsServiceClient"><see cref="OtlpCollector.MetricsService.MetricsServiceClient"/>.</param>
internal OtlpMetricsExporter(OtlpExporterOptions options, OtlpCollector.MetricsService.MetricsServiceClient metricsServiceClient = null)
/// <param name="metricsServiceClient"><see cref="OtlpCollector.MetricsService.IMetricsServiceClient"/>.</param>
internal OtlpMetricsExporter(OtlpExporterOptions options, OtlpCollector.MetricsService.IMetricsServiceClient metricsServiceClient = null)
{
this.options = options ?? throw new ArgumentNullException(nameof(options));
this.headers = GetMetadataFromHeaders(options.Headers);
Expand Down
18 changes: 17 additions & 1 deletion src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol

## Configuration

You can configure the `OtlpExporter` through `OtlpExporterOptions` properties:
You can configure the `OtlpExporter` through `OtlpExporterOptions`
properties and environment variables. The `OtlpExporterOptions`
setters take precedence over the environment variables.

## Options Properties

* `Endpoint`: Target to which the exporter is going to send traces or metrics.
The endpoint must be a valid Uri with scheme (http or https) and host, and MAY
Expand All @@ -35,6 +39,18 @@ You can configure the `OtlpExporter` through `OtlpExporterOptions` properties:
See the [`TestOtlpExporter.cs`](../../examples/Console/TestOtlpExporter.cs) for
an example of how to use the exporter.

## Environment Variables

The following environment variables can be used to override the default
values of the `OtlpExporterOptions`
(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md)).

| Environment variable | `OtlpExporterOptions` property |
| ------------------------------| -------------------------------|
| `OTEL_EXPORTER_OTLP_ENDPOINT` | `Endpoint` |
| `OTEL_EXPORTER_OTLP_HEADERS` | `Headers` |
| `OTEL_EXPORTER_OTLP_TIMEOUT` | `TimeoutMilliseconds` |

## Special case when using insecure channel

If your application is [.NET Standard
Expand Down
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.2.0-alpha1

Released 2021-Jul-23
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);
}
}
}
18 changes: 15 additions & 3 deletions src/OpenTelemetry.Exporter.Zipkin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ method on `TracerProviderBuilder`.

## Configuration

You can configure the `ZipkinExporter` through
`ZipkinExporterOptions` properties:
You can configure the `ZipkinExporter` through `ZipkinExporterOptions`
and environment variables. The `ZipkinExporterOptions` setters
take precedence over the environment variables.

### Configuration using Properties

* `ServiceName`: Name of the service reporting telemetry. If the `Resource`
associated with the telemetry has "service.name" defined, then it'll be
Expand All @@ -41,7 +44,7 @@ See
[`TestZipkinExporter.cs`](../../examples/Console/TestZipkinExporter.cs)
for example use.

## Configuration using Dependency Injection
### Configuration using Dependency Injection

This exporter allows easy configuration of `ZipkinExporterOptions` from
dependency injection container, when used in conjunction with
Expand All @@ -50,6 +53,15 @@ dependency injection container, when used in conjunction with
See the [Startup](../../examples/AspNetCore/Startup.cs) class of the ASP.NET
Core application for example use.

### Configuration using Environment Variables

The following environment variables can be used to override the default
values of the `ZipkinExporterOptions`.

| Environment variable | `ZipkinExporterOptions` property |
| --------------------------------| -------------------------------- |
| `OTEL_EXPORTER_ZIPKIN_ENDPOINT` | `Endpoint` |

## References

* [OpenTelemetry Project](https://opentelemetry.io/)
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 @@ -25,12 +26,31 @@ namespace OpenTelemetry.Exporter
public sealed class ZipkinExporterOptions
{
internal const int DefaultMaxPayloadSizeInBytes = 4096;
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)
{
this.Endpoint = new Uri(DefaultZipkinEndpoint);
ZipkinExporterEventSource.Log.FailedEndpointInitialization(ex);
}
}

/// <summary>
/// Gets or sets Zipkin endpoint address. See https://zipkin.io/zipkin-api/#/default/post_spans.
/// 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
12 changes: 12 additions & 0 deletions src/OpenTelemetry/Metrics/AggregatorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ internal List<IMetric> Collect(bool isDelta, DateTimeOffset dt)
{
var collectedMetrics = new List<IMetric>();

if (this.tag0Metrics != null)
{
foreach (var aggregator in this.tag0Metrics)
{
var m = aggregator.Collect(dt, isDelta);
if (m != null)
{
collectedMetrics.Add(m);
}
}
}

// Lock to prevent new time series from being added
// until collect is done.
lock (this.lockKeyValue2MetricAggs)
Expand Down
Loading

0 comments on commit 5b4b8cb

Please sign in to comment.