Skip to content

Commit

Permalink
[Exporter.Geneva] Add support for ILogger scopes (open-telemetry#390)
Browse files Browse the repository at this point in the history
* Add support for ILogger scopes
  • Loading branch information
utpilla authored and NathanielRN committed Jun 6, 2022
1 parent d9fef1d commit ec5f94f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Add support for exporting `ILogger` scopes.
[390](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/390)

## 1.3.0-beta.1 [2022-May-27]

* Enable PassThru TableNameMappings using the logger category name.
Expand Down
38 changes: 38 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,44 @@ internal int SerializeLogRecord(LogRecord logRecord)
cntFields += 1;
}

ushort scopeDepth = 0;
int indexArrayLength = 0;
logRecord.ForEachScope(ProcessScope, (object)null);
void ProcessScope(LogRecordScope scope, object state)
{
if (++scopeDepth == 1)
{
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, "scopes");
cursor = MessagePackSerializer.WriteArrayHeader(buffer, cursor, ushort.MaxValue);
indexArrayLength = cursor - 2;
}

cursor = MessagePackSerializer.WriteMapHeader(buffer, cursor, ushort.MaxValue);
int indexMapSizeScope = cursor - 2;
ushort keysCount = 0;

foreach (KeyValuePair<string, object> scopeItem in scope)
{
string key = "scope";
if (!string.IsNullOrEmpty(scopeItem.Key))
{
key = scopeItem.Key;
}

cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, key);
cursor = MessagePackSerializer.Serialize(buffer, cursor, scopeItem.Value);
keysCount++;
}

MessagePackSerializer.WriteUInt16(buffer, indexMapSizeScope, keysCount);
}

if (scopeDepth > 0)
{
MessagePackSerializer.WriteUInt16(buffer, indexArrayLength, scopeDepth);
cntFields += 1;
}

if (hasEnvProperties)
{
// Iteration #2 - Get all "other" fields and collapse them into single field
Expand Down

0 comments on commit ec5f94f

Please sign in to comment.