JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.79k stars 441 forks source link

OpenTelemetry: Marten does not create activities #3195

Closed dvlprx closed 3 months ago

dvlprx commented 3 months ago

Hi community,

I just upgraded to version 7.10 and I can not get otel-activities, to be created.

Question 1

Is it enough to just add "Marten" to the observed sources, to let marten write activities?

This (08.05.2024): https://martendb.io/otel says, just adding "Marten" as observed tracing-source is enough.

This (09.12.2023): https://event-driven.io/en/set_up_opentelemetry_wtih_event_sourcing_and_marten/ I expect to be the do-it-yourself way, but is not necessary with 7.10, to let marten write activities?

Question 2

Could you please tell me what I am missing :/

OpenTelemetry:

sc.AddOpenTelemetry().WithTracing(tracerBuilder =>
{
    ...
    builder.AddNpgsql();
    builder.AddSource($"Marten");
    ...
}

Marten:

sc.AddMarten(sp =>
{
    ...

    opts.Events.MetadataConfig.CorrelationIdEnabled = true;
    opts.Events.MetadataConfig.CausationIdEnabled = true;

    opts.Policies.ForAllDocuments(x =>
    {
        x.Metadata.CausationId.Enabled = true;
        x.Metadata.CorrelationId.Enabled = true;
    });
}

Question 3

is setting the marten correlation options necessary at all, to let it just write activities (if we don't care about the correlation/causation stuff)

Reproduce

using var a = Tracer.StartActivity(this.VmInstanceId);
await using var session = testSp.GetRequiredService<IDocumentStore>().LightweightSession();
var _ = await session.Events.FetchStreamAsync($"SomeTestStream");

=> this gives me an activity from npgsql with a "received-first-response" event, but it DOES NOT include the db.statement tag

using var a = Tracer.StartActivity(this.VmInstanceId);
await using var session = testSp.GetRequiredService<IDocumentStore>().LightweightSession();
var newEvent = new EventTestMethodInvoked());
var _ = session.Events.Append($"SomeTestStream", newEvent);

=> this gives me NO ACTIVITY at all

Any help, or pointing in the right direction would be very very appreciated ... got stuck on this the whole day.