Skip to content

Commit

Permalink
Merge pull request #25 from joegoldman2/update-attributes
Browse files Browse the repository at this point in the history
Update attributes to be compliant with OpenTelemetry
  • Loading branch information
jbogard authored Feb 14, 2024
2 parents b6480f4 + 20fb06e commit 65a037e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ private void Handle(CommandStartedEvent @event)
activity.AddTag("db.name", @event.DatabaseNamespace?.DatabaseName);
activity.AddTag("db.mongodb.collection", collectionName);
activity.AddTag("db.operation", @event.CommandName);
activity.AddTag("net.transport", "ip_tcp");
activity.AddTag("network.transport", "tcp");

var endPoint = @event.ConnectionId?.ServerId?.EndPoint;
switch (endPoint)
{
case IPEndPoint ipEndPoint:
activity.AddTag("net.peer.port", ipEndPoint.Port.ToString());
activity.AddTag("net.sock.peer.addr", ipEndPoint.Address.ToString());
activity.AddTag("network.peer.address", ipEndPoint.Address.ToString());
activity.AddTag("network.peer.port", ipEndPoint.Port.ToString());
break;
case DnsEndPoint dnsEndPoint:
activity.AddTag("net.peer.name", dnsEndPoint.Host);
activity.AddTag("net.peer.port", dnsEndPoint.Port.ToString());
activity.AddTag("server.address", dnsEndPoint.Host);
activity.AddTag("server.port", dnsEndPoint.Port.ToString());
break;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ private void Handle(CommandFailedEvent @event)
activity.AddTag("exception.message", @event.Failure.Message);
activity.AddTag("exception.stacktrace", @event.Failure.StackTrace);
}

activity.SetStatus(ActivityStatusCode.Error);
activity.Stop();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public void Should_record_all_data()
activity.Tags.SingleOrDefault(t => t.Key == "db.mongodb.collection").Value.ShouldBe("my_collection");
activity.Tags.SingleOrDefault(t => t.Key == "db.operation").Value.ShouldBe("update");
activity.Tags.SingleOrDefault(t => t.Key == "db.statement").ShouldBe(default);
activity.Tags.SingleOrDefault(t => t.Key == "net.peer.name").Value.ShouldBe("localhost");
activity.Tags.SingleOrDefault(t => t.Key == "net.peer.port").Value.ShouldBe("8000");
activity.Tags.SingleOrDefault(t => t.Key == "server.address").Value.ShouldBe("localhost");
activity.Tags.SingleOrDefault(t => t.Key == "server.port").Value.ShouldBe("8000");
activity.Tags.SingleOrDefault(t => t.Key == "otel.status_code").Value.ShouldBe("OK");

stopFired = true;
Expand Down

0 comments on commit 65a037e

Please sign in to comment.