Skip to content

Commit

Permalink
Merge branch 'main' into bug/eksssl
Browse files Browse the repository at this point in the history
  • Loading branch information
srprash authored May 12, 2022
2 parents cf49b8e + 055c156 commit 7f76cf5
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: OpenTelemetry.Extensions.PersistentStorage.Abstractions
about: Issue with OpenTelemetry.Extensions.PersistentStorage.Abstractions
labels: comp:extensions.persistentstorage.abstractions
---

# Issue with OpenTelemetry.Extensions.PersistentStorage.Abstractions

List of [all OpenTelemetry NuGet
packages](https://www.nuget.org/profiles/OpenTelemetry) and version that you are
using (e.g. `OpenTelemetry 1.0.2`):

* TBD

Runtime version (e.g. `net462`, `net48`, `netcoreapp3.1`, `net6.0` etc. You can
find this information from the `*.csproj` file):

* TBD

**Is this a feature request or a bug?**

* [ ] Feature Request
* [ ] Bug

**What is the expected behavior?**

What do you expect to see?

**What is the actual behavior?**

What did you see instead? If you are reporting a bug, create a self-contained
project using the template of your choice and apply the minimum required code to
result in the issue you're observing. We will close this issue if:

* The repro project you share with us is complex. We can't investigate custom
projects, so don't point us to such, please.
* If we can not reproduce the behavior you're reporting.

## Additional Context

Add any other context about the feature request here.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format-md.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
runs-on: ubuntu-latest

steps:
run: 'echo "No build required"'
- run: 'echo "No build required"'
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Throw exception when `TableNameMappings` contains a `null` value.
[322](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/322)

* TraceExporter bug fix to not export non-recorded Activities.
[352](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/352)

## 1.2.6 [2022-Apr-21]

* Set GenevaMetricExporter temporality preference back to Delta.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System;
using System.Diagnostics;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;

Expand Down Expand Up @@ -48,7 +47,7 @@ private static TracerProviderBuilder AddGenevaTraceExporter(this TracerProviderB
}
else
{
return builder.AddProcessor(new ReentrantExportProcessor<Activity>(exporter));
return builder.AddProcessor(new ReentrantActivityExportProcessor(exporter));
}
}
}
169 changes: 167 additions & 2 deletions src/OpenTelemetry.Exporter.Geneva/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,171 @@
# Geneva Exporters for OpenTelemetry .NET
# Geneva Exporter for OpenTelemetry .NET

[![NuGet](https://img.shields.io/nuget/v/OpenTelemetry.Exporter.Geneva.svg)](https://www.nuget.org/packages/OpenTelemetry.Exporter.Geneva)
[![NuGet](https://img.shields.io/nuget/dt/OpenTelemetry.Exporter.Geneva.svg)](https://www.nuget.org/packages/OpenTelemetry.Exporter.Geneva)

TBD
The Geneva Exporter exports telemetry to
[Event Tracing for Windows (ETW)](https://docs.microsoft.com/windows/win32/etw/about-event-tracing)
or to a
[Unix Domain Socket (UDS)](https://en.wikipedia.org/wiki/Unix_domain_socket)
on the local machine.

## Installation

```shell
dotnet add package OpenTelemetry.Exporter.Geneva
```

## Configuration

The three types of telemetry are handled separately in OpenTelemetry.
Therefore, each type of telemetry **must be** enabled separately.

### Enable Logs

Install the latest stable version of
[`Microsoft.Extensions.Logging`](https://www.nuget.org/packages/Microsoft.Extensions.Logging/)

```shell
dotnet add package OpenTelemetry.Exporter.Geneva
```

This snippet shows how to configure the Geneva Exporter for Logs

```csharp
using var loggerFactory = LoggerFactory.Create(loggingBuilder => loggingBuilder
.AddOpenTelemetry(openTelemetryLoggerOptions =>
{
openTelemetryLoggerOptions.AddGenevaLogExporter(genevaExporterOptions =>
{
genevaExporterOptions.ConnectionString = "EtwSession=OpenTelemetry";
});
}));
```

The above code must be in application startup. In case of ASP.NET Core
applications, this should be in `ConfigureServices` of `Startup` class.
For ASP.NET applications, this should be in `Global.aspx.cs`.

Since OpenTelemetry .NET SDK is a
[LoggingProvider](https://docs.microsoft.com/dotnet/core/extensions/logging-providers),
use the built-in mechanism to apply [Log
filtering](https://docs.microsoft.com/dotnet/core/extensions/logging?tabs=command-line#how-filtering-rules-are-applied).
This filtering lets you control the Logs that are sent to each registered
provider, including the OpenTelemetry provider. `OpenTelemetry` is the
[alias](https://docs.microsoft.com/dotnet/api/microsoft.extensions.logging.provideraliasattribute)
for `OpenTelemetryLoggerProvider`, that may be used when configuring filtering
rules.

**NOTE:** _Some application types (e.g. [ASP.NET
Core](https://docs.microsoft.com/aspnet/core/fundamentals/logging/#configure-logging-1))
have default logging settings. Please review them to make sure
`OpenTelemetryLoggingProvider` is configured to receive Logs of appropriate
levels and category.

### Enable Traces

This snippet shows how to configure the Geneva Exporter for Traces

```csharp
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(new AlwaysOnSampler())
.AddSource("DemoSource")
.AddGenevaTraceExporter(options => {
options.ConnectionString = "EtwSession=OpenTelemetry";
})
.Build();
```

The above code must be in application startup. In case of ASP.NET Core
applications, this should be in `ConfigureServices` of `Startup` class.
For ASP.NET applications, this should be in `Global.aspx.cs`.

### GenevaExporterOptions (for Logs and Traces)

`GenevaExporterOptions` contains various options to configure the Geneva
Exporter.

#### `ConnectionString` (required for Logs and Traces)

On Linux the connection string has the format `Endpoint=unix:{UDS Path}`.

On Windows the connection string has the format `EtwSession={ETW session}`.

#### `CustomFields` (optional)

A list of fields which should be stored as individual table columns.

#### `PrepopulatedFields` (optional)

This is a collection of fields that will be applied to all the Logs and Traces
sent through this exporter.

#### `TableNameMappings` (optional)

This defines the mapping for the table name used to store Logs and Traces.

The default table name used for Traces is `Span`. For changing the table name
for Traces, add an entry with key as `Span`, and value as the custom table name.

The default table name used for Logs is `Log`. Mappings can be specified for
each
[category](https://docs.microsoft.com/dotnet/core/extensions/logging#log-category)
of the log. For changing the default table name for Logs, add an entry with key
as `*`, and value as the custom table name.

### Enable Metrics

This snippet shows how to configure the Geneva Exporter for Metrics

```csharp
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("TestMeter")
.AddGenevaMetricExporter(options =>
{
options.ConnectionString = "Account=OTelMonitoringAccount;Namespace=OTelMetricNamespace";
})
.Build();
```

The above code must be in application startup. In case of ASP.NET Core
applications, this should be in `ConfigureServices` of `Startup` class.
For ASP.NET applications, this should be in `Global.aspx.cs`.

### GenevaMetricExporterOptions (for Metrics)

`GenevaMetricExporterOptions` contains various options which are required to
configure the GenevaMetricExporter.

#### `ConnectionString` (required for Metrics)

On Windows **DO NOT** provide an ETW session name for Metrics, only specify
Account and Namespace. For example:
`Account={MetricAccount};Namespace={MetricNamespace}`.

On Linux provide an `Endpoint` in addition to the `Account` and `Namespace`.
For example:
`Endpoint=unix:{UDS Path};Account={MetricAccount};Namespace={MetricNamespace}`.

#### `MetricExportIntervalMilliseconds` (optional)

Set the exporter's periodic time interval to export Metrics. The default value
is 20000 milliseconds.

#### `PrepopulatedMetricDimensions` (optional)

This is a collection of the dimensions that will be applied to _every_ metric
exported by the exporter.

## Troubleshooting

Before digging into a problem, check if you hit a known issue by looking at the
[CHANGELOG.md](./CHANGELOG.md) and [GitHub
issues](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues).

Geneva Exporters uses an
[EventSource](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventsource)
with the name "OpenTelemetry-Exporter-Geneva" for its internal logging. Please
follow the [troubleshooting guide for OpenTelemetry
.NET](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry#troubleshooting)
for instructions on seeing Logs from the geneva exporter, as well as other
OpenTelemetry components.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// <copyright file="ReentrantActivityExportProcessor.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.Diagnostics;

namespace OpenTelemetry.Exporter.Geneva;

// This export processor exports without synchronization.
// Once OpenTelemetry .NET officially support this,
// we can get rid of this class.
// This is currently only used in ETW export, where we know
// that the underlying system is safe under concurrent calls.
internal class ReentrantActivityExportProcessor : ReentrantExportProcessor<Activity>
{
public ReentrantActivityExportProcessor(BaseExporter<Activity> exporter)
: base(exporter)
{
}

protected override void OnExport(Activity data)
{
if (data.Recorded)
{
base.OnExport(data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public abstract class PersistentBlob
/// </returns>
public bool TryRead([NotNullWhen(true)] out byte[]? buffer)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryRead(out buffer);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
{
// TODO: log exception.
buffer = null;
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -63,17 +63,17 @@ public bool TryRead([NotNullWhen(true)] out byte[]? buffer)
/// </returns>
public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryWrite(buffer, leasePeriodMilliseconds);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
{
// TODO: log exception.
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -87,17 +87,17 @@ public bool TryWrite(byte[] buffer, int leasePeriodMilliseconds = 0)
/// </returns>
public bool TryLease(int leasePeriodMilliseconds)
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryLease(leasePeriodMilliseconds);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
{
// TODO: log exception.
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

/// <summary>
Expand All @@ -108,17 +108,17 @@ public bool TryLease(int leasePeriodMilliseconds)
/// </returns>
public bool TryDelete()
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
return this.OnTryDelete();
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
{
// TODO: log exception.
return false;
}
#pragma warning restore CA1031 // Do not catch general exception types
}

protected abstract bool OnTryRead([NotNullWhen(true)] out byte[]? buffer);
Expand Down
Loading

0 comments on commit 7f76cf5

Please sign in to comment.