forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azure Monitor Exporter: LogExporter (Azure#17117)
* saving wip * tests * wip * log details * mark classes internal while WIP * tests * disable Task.Delay * cleanup * cleanup * cleanup * fix datetime * include condition; if not default * todo
- Loading branch information
1 parent
98dfaba
commit 6982a61
Showing
8 changed files
with
248 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...icrosoft.OpenTelemetry.Exporter.AzureMonitor/src/AzureMonitorExporterLoggingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
using Microsoft.OpenTelemetry.Exporter.AzureMonitor; | ||
|
||
using OpenTelemetry; | ||
using OpenTelemetry.Logs; | ||
|
||
namespace Microsoft.Extensions.Logging | ||
{ | ||
internal static class AzureMonitorExporterLoggingExtensions | ||
{ | ||
public static OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(this OpenTelemetryLoggerOptions loggerOptions, Action<AzureMonitorExporterOptions> configure = null) | ||
{ | ||
if (loggerOptions == null) | ||
{ | ||
throw new ArgumentNullException(nameof(loggerOptions)); | ||
} | ||
|
||
var options = new AzureMonitorExporterOptions(); | ||
configure?.Invoke(options); | ||
|
||
return loggerOptions.AddProcessor(new BatchExportProcessor<LogRecord>(new AzureMonitorLogExporter(options))); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
sdk/monitor/Microsoft.OpenTelemetry.Exporter.AzureMonitor/src/AzureMonitorLogExporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading; | ||
|
||
using Azure.Core.Pipeline; | ||
|
||
using OpenTelemetry; | ||
using OpenTelemetry.Logs; | ||
|
||
namespace Microsoft.OpenTelemetry.Exporter.AzureMonitor | ||
{ | ||
internal class AzureMonitorLogExporter : BaseExporter<LogRecord> | ||
{ | ||
private readonly ITransmitter Transmitter; | ||
private readonly AzureMonitorExporterOptions options; | ||
private readonly string instrumentationKey; | ||
|
||
public AzureMonitorLogExporter(AzureMonitorExporterOptions options) : this(options, new AzureMonitorTransmitter(options)) | ||
{ | ||
} | ||
|
||
internal AzureMonitorLogExporter(AzureMonitorExporterOptions options, ITransmitter transmitter) | ||
{ | ||
this.options = options ?? throw new ArgumentNullException(nameof(options)); | ||
ConnectionString.ConnectionStringParser.GetValues(this.options.ConnectionString, out this.instrumentationKey, out _); | ||
|
||
this.Transmitter = transmitter; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override ExportResult Export(in Batch<LogRecord> batch) | ||
{ | ||
// Prevent Azure Monitor's HTTP operations from being instrumented. | ||
using var scope = SuppressInstrumentationScope.Begin(); | ||
|
||
try | ||
{ | ||
var telemetryItems = AzureMonitorConverter.Convert(batch, this.instrumentationKey); | ||
|
||
// TODO: Handle return value, it can be converted as metrics. | ||
// TODO: Validate CancellationToken and async pattern here. | ||
this.Transmitter.TrackAsync(telemetryItems, false, CancellationToken.None).EnsureCompleted(); | ||
return ExportResult.Success; | ||
} | ||
catch (Exception ex) | ||
{ | ||
AzureMonitorExporterEventSource.Log.Write($"FailedToExport{EventLevelSuffix.Error}", ex.LogAsyncException()); | ||
return ExportResult.Failure; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters