Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted OTEL tags to correspond spec #18

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ private void Handle(CommandStartedEvent @event)
activity.DisplayName = collectionName == null ? $"mongodb.{@event.CommandName}" : $"{collectionName}.{@event.CommandName}";

activity.AddTag("db.system", "mongodb");
activity.AddTag("db.connection_id", @event.ConnectionId?.ToString());
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");

var endPoint = @event.ConnectionId?.ServerId?.EndPoint;
switch (endPoint)
{
case IPEndPoint ipEndPoint:
activity.AddTag("db.user", $"mongodb://{ipEndPoint.Address}:{ipEndPoint.Port}");
activity.AddTag("net.peer.ip", ipEndPoint.Address.ToString());
activity.AddTag("net.peer.port", ipEndPoint.Port.ToString());
activity.AddTag("net.sock.peer.addr", ipEndPoint.Address.ToString());
break;
case DnsEndPoint dnsEndPoint:
activity.AddTag("db.user", $"mongodb://{dnsEndPoint.Host}:{dnsEndPoint.Port}");
activity.AddTag("net.peer.name", dnsEndPoint.Host);
activity.AddTag("net.peer.port", dnsEndPoint.Port.ToString());
break;
Expand All @@ -85,7 +86,7 @@ private void Handle(CommandSucceededEvent @event)
{
WithReplacedActivityCurrent(activity, () =>
{
activity.AddTag("otel.status_code", "Ok");
activity.AddTag("otel.status_code", "OK");
activity.Stop();
});
}
Expand All @@ -99,11 +100,11 @@ private void Handle(CommandFailedEvent @event)
{
if (activity.IsAllDataRequested)
{
activity.AddTag("otel.status_code", "Error");
activity.AddTag("otel.status_code", "ERROR");
activity.AddTag("otel.status_description", @event.Failure.Message);
activity.AddTag("error.type", @event.Failure.GetType().FullName);
activity.AddTag("error.msg", @event.Failure.Message);
activity.AddTag("error.stack", @event.Failure.StackTrace);
activity.AddTag("exception.type", @event.Failure.GetType().FullName);
activity.AddTag("exception.message", @event.Failure.Message);
activity.AddTag("exception.stacktrace", @event.Failure.StackTrace);
}

activity.Stop();
Expand All @@ -125,4 +126,4 @@ private static void WithReplacedActivityCurrent(Activity activity, Action action
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void Should_start_and_log_failed_activity()
activity.OperationName.ShouldBe(DiagnosticsActivityEventSubscriber.ActivityName);
var statusTag = activity.Tags.SingleOrDefault(t => t.Key == "otel.status_code");
statusTag.ShouldNotBe(default);
statusTag.Value.ShouldBe("Error");
statusTag.Value.ShouldBe("ERROR");
exceptionFired = true;
}
};
Expand Down Expand Up @@ -185,8 +185,13 @@ public void Should_record_all_data()
instanceTag.Value.ShouldBe("test");

activity.Tags.SingleOrDefault(t => t.Key == "db.system").Value.ShouldBe("mongodb");
activity.Tags.SingleOrDefault(t => t.Key == "db.connection_id").Value.ShouldBe("{ ServerId : { ClusterId : 42, EndPoint : \"Unspecified/localhost:8000\" }, LocalValue : 43 }");
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 == "otel.status_code").Value.ShouldBe("OK");

stopFired = true;
}
Expand All @@ -199,7 +204,7 @@ public void Should_record_all_data()
behavior.TryGetEventHandler<CommandStartedEvent>(out var startEvent).ShouldBeTrue();
behavior.TryGetEventHandler<CommandSucceededEvent>(out var stopEvent).ShouldBeTrue();

var connectionId = new ConnectionId(new ServerId(new ClusterId(), new DnsEndPoint("localhost", 8000)));
var connectionId = new ConnectionId(new ServerId(new ClusterId(42), new DnsEndPoint("localhost", 8000)), 43);
var databaseNamespace = new DatabaseNamespace("test");
var command = new BsonDocument(new Dictionary<string, object>
{
Expand All @@ -211,7 +216,7 @@ public void Should_record_all_data()
startFired.ShouldBeTrue();
stopFired.ShouldBeTrue();
}

[Fact]
public void Should_record_command_text_when_option_set()
{
Expand Down Expand Up @@ -334,4 +339,4 @@ public void Should_fire_activity_when_filter_is_null_or_return_true_and_should_n
activities.Count.ShouldBe(shouldFireActivity ? 1 : 0);
}
}
}
}