Skip to content

Commit

Permalink
Update example and Readme for otlp log exporter (#4747)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishweshbankwar authored Aug 10, 2023
1 parent cf0b4d7 commit a4fae4f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
6 changes: 6 additions & 0 deletions examples/Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ internal class LogsOptions

[Option('p', "protocol", HelpText = "Transport protocol used by OTLP exporter. Supported values: grpc and http/protobuf. Only applicable if Exporter is OTLP", Default = "grpc")]
public string Protocol { get; set; }

[Option("processorType", Default = "batch", HelpText = "export processor type. Supported values: simple and batch", Required = false)]
public string ProcessorType { get; set; }

[Option("scheduledDelay", Default = 5000, HelpText = "The delay interval in milliseconds between two consecutive exports.", Required = false)]
public int ScheduledDelayInMilliseconds { get; set; }
}

[Verb("inmemory", HelpText = "Specify the options required to test InMemory Exporter")]
Expand Down
31 changes: 28 additions & 3 deletions examples/Console/TestLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Logs;

namespace Examples.Console;
Expand Down Expand Up @@ -73,12 +74,36 @@ internal static object Run(LogsOptions options)
System.Console.WriteLine($"Export protocol {options.Protocol} is not supported. Default protocol 'grpc' will be used.");
}

opt.AddOtlpExporter(otlpOptions =>
var processorType = ExportProcessorType.Batch;
if (options.ProcessorType.Trim().ToLower().Equals("batch"))
{
otlpOptions.Protocol = protocol;
processorType = ExportProcessorType.Batch;
}
else if (options.Protocol.Trim().ToLower().Equals("simple"))
{
processorType = ExportProcessorType.Simple;
}
else
{
System.Console.WriteLine($"Export processor type {options.ProcessorType} is not supported. Default processor type 'batch' will be used.");
}

opt.AddOtlpExporter((exporterOptions, processorOptions) =>
{
exporterOptions.Protocol = protocol;
if (!string.IsNullOrWhiteSpace(options.Endpoint))
{
otlpOptions.Endpoint = new Uri(options.Endpoint);
exporterOptions.Endpoint = new Uri(options.Endpoint);
}

if (processorType == ExportProcessorType.Simple)
{
processorOptions.ExportProcessorType = ExportProcessorType.Simple;
}
else
{
processorOptions.ExportProcessorType = ExportProcessorType.Batch;
processorOptions.BatchExportProcessorOptions = new BatchExportLogRecordProcessorOptions() { ScheduledDelayMilliseconds = options.ScheduledDelayInMilliseconds };
}
});
}
Expand Down
59 changes: 50 additions & 9 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ environment variables.

## Enable Log Exporter

// TODO
```csharp
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.AddOtlpExporter();
});
});
```

By default, `AddOtlpExporter()` pairs the OTLP Log Exporter with a [batching
processor](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#batching-processor).
See [`TestLogs.cs`](../../examples/Console/TestLogs.cs) for example on how to
customize the `LogRecordExportProcessorOptions` or see the [Environment
Variables](#environment-variables) section below on how to customize using
environment variables.

## Configuration

Expand All @@ -82,14 +97,6 @@ TODO: Show metrics specific configuration (i.e MetricReaderOptions).

## OtlpExporterOptions

* `ExportProcessorType`: Whether the exporter should use [Batch or Simple
exporting
processor](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#built-in-span-processors).
The default is Batch.

* `BatchExportProcessorOptions`: Configuration options for the batch exporter.
Only used if ExportProcessorType is set to Batch.

* `Protocol`: OTLP transport protocol. Supported values:
`OtlpExportProtocol.Grpc` and `OtlpExportProtocol.HttpProtobuf`.
The default is `OtlpExportProtocol.Grpc`.
Expand All @@ -109,6 +116,16 @@ TODO: Show metrics specific configuration (i.e MetricReaderOptions).

* `TimeoutMilliseconds` : Max waiting time for the backend to process a batch.

The following options are only applicable to `OtlpTraceExporter`:

* `ExportProcessorType`: Whether the exporter should use [Batch or Simple
exporting
processor](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#built-in-span-processors).
The default is Batch.

* `BatchExportProcessorOptions`: Configuration options for the batch exporter.
Only used if ExportProcessorType is set to Batch.

See the [`TestOtlpExporter.cs`](../../examples/Console/TestOtlpExporter.cs) for
an example of how to use the exporter.

Expand All @@ -125,6 +142,30 @@ values of the `OtlpExporterOptions`
| `OTEL_EXPORTER_OTLP_TIMEOUT` | `TimeoutMilliseconds` |
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `Protocol` (`grpc` or `http/protobuf`)|

The following environment variables can be used to override the default values
for `BatchExportProcessorOptions` in case of `OtlpTraceExporter` (following the
[OpenTelemetry
specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#batch-span-processor))

| Environment variable | `OtlpExporterOptions.BatchExportProcessorOptions` property |
| ---------------------------------| ------------------------------------------------------------|
| `OTEL_BSP_SCHEDULE_DELAY` | `ScheduledDelayMilliseconds` |
| `OTEL_BSP_EXPORT_TIMEOUT` | `ExporterTimeoutMilliseconds` |
| `OTEL_BSP_MAX_QUEUE_SIZE` | `MaxQueueSize` |
| `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` | `MaxExportBatchSize` |

The following environment variables can be used to override the default values
for `BatchExportProcessorOptions` in case of `OtlpLogExporter` (following the
[OpenTelemetry
specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#batch-logrecord-processor))

| Environment variable | `LogRecordExportProcessorOptions.BatchExportProcessorOptions` property |
| ----------------------------------| ------------------------------------------------------------------------|
| `OTEL_BLRP_SCHEDULE_DELAY` | `ScheduledDelayMilliseconds` |
| `OTEL_BLRP_EXPORT_TIMEOUT` | `ExporterTimeoutMilliseconds` |
| `OTEL_BLRP_MAX_QUEUE_SIZE` | `MaxQueueSize` |
| `OTEL_BLRP_MAX_EXPORT_BATCH_SIZE` | `MaxExportBatchSize` |

The following environment variables can be used to override the default
values of the `PeriodicExportingMetricReaderOptions`
(following the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.12.0/specification/sdk-environment-variables.md#periodic-exporting-metricreader).
Expand Down

0 comments on commit a4fae4f

Please sign in to comment.