forked from open-telemetry/opentelemetry-dotnet
-
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.
Added JaegerLogRecordProcessor to send logs from Microsoft.Extensions…
….Logging.ILogger to Jaeger (open-telemetry#1739)
- Loading branch information
Sergey Ivanov
committed
Feb 11, 2021
1 parent
cde2060
commit c132085
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/OpenTelemetry.Exporter.Jaeger/JaegerLogRecordProcessor.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 file="JaegerLogRecordProcessor.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; | ||
using OpenTelemetry.Logs; | ||
|
||
namespace OpenTelemetry.Exporter.Jaeger | ||
{ | ||
public class JaegerLogRecordProcessor : BaseProcessor<LogRecord> | ||
{ | ||
private readonly JaegerLogRecordProcessorOptions options; | ||
|
||
public JaegerLogRecordProcessor(JaegerLogRecordProcessorOptions options) | ||
{ | ||
this.options = options ?? new JaegerLogRecordProcessorOptions(); | ||
} | ||
|
||
public override void OnEnd(LogRecord data) | ||
{ | ||
if (Activity.Current != null) | ||
{ | ||
var tags = new ActivityTagsCollection | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
CodeBlanch
|
||
{ | ||
{ nameof(data.CategoryName), data.CategoryName }, | ||
{ nameof(data.EventId), data.EventId }, | ||
{ nameof(data.Exception), data.Exception }, | ||
{ nameof(data.LogLevel), data.LogLevel }, | ||
{ nameof(data.SpanId), data.SpanId }, | ||
{ nameof(data.State), data.State }, | ||
{ nameof(data.Timestamp), data.Timestamp }, | ||
{ nameof(data.TraceFlags), data.TraceFlags }, | ||
{ nameof(data.TraceId), data.TraceId }, | ||
{ nameof(data.TraceState), data.TraceState }, | ||
}; | ||
|
||
var activityEvent = new ActivityEvent(data.CategoryName, default, tags); | ||
Activity.Current.AddEvent(activityEvent); | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/OpenTelemetry.Exporter.Jaeger/JaegerLogRecordProcessorOptions.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,22 @@ | ||
// <copyright file="JaegerProcessorLoggingOptions.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> | ||
|
||
namespace OpenTelemetry.Exporter.Jaeger | ||
{ | ||
public class JaegerLogRecordProcessorOptions | ||
{ | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/OpenTelemetry.Exporter.Jaeger/JaegerLoggerProcessorExtensions.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,43 @@ | ||
// <copyright file="JaegerExporterLoggingExtensions.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 OpenTelemetry.Logs; | ||
|
||
namespace OpenTelemetry.Exporter.Jaeger | ||
{ | ||
public static class JaegerLoggerProcessorExtensions | ||
{ | ||
/// <summary> | ||
/// Adds Jaeger LogRecord Processor as a configuration to the OpenTelemetry ILoggingBuilder. | ||
/// </summary> | ||
/// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param> | ||
/// <param name="configure">Exporter configuration options.</param> | ||
/// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns> | ||
/// <exception cref="ArgumentNullException"><paramref name="loggerOptions"/> is <c>null</c>.</exception> | ||
public static OpenTelemetryLoggerOptions AddJaegerLogRecordProcessor(this OpenTelemetryLoggerOptions loggerOptions, Action<JaegerLogRecordProcessorOptions> configure = null) | ||
{ | ||
if (loggerOptions == null) | ||
{ | ||
throw new ArgumentNullException(nameof(loggerOptions)); | ||
} | ||
|
||
var options = new JaegerLogRecordProcessorOptions(); | ||
configure?.Invoke(options); | ||
return loggerOptions.AddProcessor(new JaegerLogRecordProcessor(options)); | ||
} | ||
} | ||
} |
Sometimes logs have additional properties. Is it possible to make this list dynamic, depending on the log message?