Skip to content

Commit

Permalink
Merge branch 'main' into 2361_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra authored Apr 21, 2022
2 parents 795aaf2 + 1918e4b commit d8deca4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Merging test results
run: reportgenerator -reports:TestResults/**/*.xml -targetdir:TestResults -reporttypes:Cobertura -assemblyFilters:"-microsoft.data.sqlclient*;-grpc.core*;-opentracing*"

- uses: codecov/codecov-action@v3.0.0
- uses: codecov/codecov-action@v3.1.0
with:
file: TestResults/Cobertura.xml
env_vars: OS
Expand Down
6 changes: 4 additions & 2 deletions docs/logs/getting-started/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public static void Main()
{
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options => options
.AddConsoleExporter());
builder.AddOpenTelemetry(options =>
{
options.AddConsoleExporter();
});
});

var logger = loggerFactory.CreateLogger<Program>();
Expand Down
8 changes: 7 additions & 1 deletion examples/Console/TestLogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal static object Run(LogsOptions options)
builder.AddOpenTelemetry((opt) =>
{
opt.IncludeFormattedMessage = true;
opt.IncludeScopes = true;
if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase))
{
/*
Expand Down Expand Up @@ -68,7 +69,12 @@ internal static object Run(LogsOptions options)
});

var logger = loggerFactory.CreateLogger<Program>();
logger.LogInformation("Hello from {name} {price}.", "tomato", 2.99);
using (logger.BeginScope("My scope 1 with {food} and {color}", "apple", "green"))
using (logger.BeginScope("My scope 2 with {food} and {color}", "banana", "yellow"))
{
logger.LogInformation("Hello from {name} {price}.", "tomato", 2.99);
}

return null;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* LogExporter to support Logging Scopes.
([#3277](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3217))

## 1.3.0-beta.1

Released 2022-Apr-15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Google.Protobuf;
using Google.Protobuf.Collections;
Expand Down Expand Up @@ -132,8 +133,19 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord)
otlpLogRecord.Flags = (uint)logRecord.TraceFlags;
}

// TODO: Add additional attributes from scope and state
// Might make sense to take an approach similar to https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/897b734aa5ea9992538f04f6ea6871fe211fa903/src/OpenTelemetry.Contrib.Preview/Internal/DefaultLogStateConverter.cs
int scopeDepth = -1;
logRecord.ForEachScope(ProcessScope, otlpLogRecord);

void ProcessScope(LogRecordScope scope, OtlpLogs.LogRecord otlpLog)
{
scopeDepth++;
foreach (var scopeItem in scope)
{
var scopeItemWithDepthInfo = new KeyValuePair<string, object>($"[Scope.{scopeDepth}]:{scopeItem.Key}", scopeItem.Value);
var otlpAttribute = scopeItemWithDepthInfo.ToOtlpAttribute();
otlpLog.Attributes.Add(otlpAttribute);
}
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit d8deca4

Please sign in to comment.