From 1114b4caeb5063a5412135594a3ce3829cbc846b Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Sun, 8 Feb 2026 10:28:21 -0600 Subject: [PATCH] Marten now does the Otel causation and correlation tagging directly in open session. Closes GH-4099 --- src/Marten/DocumentStore.cs | 4 ++++ src/Marten/ISessionFactory.cs | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Marten/DocumentStore.cs b/src/Marten/DocumentStore.cs index c8c31b888a..b3e35b3c1e 100644 --- a/src/Marten/DocumentStore.cs +++ b/src/Marten/DocumentStore.cs @@ -1,6 +1,7 @@ #nullable enable using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -524,6 +525,9 @@ private IDocumentSession openSession(SessionOptions options) _ => throw new ArgumentOutOfRangeException(nameof(SessionOptions.Tracking)) }; + session.CorrelationId = Activity.Current?.RootId; + session.CausationId = Activity.Current?.ParentId; + return session; } diff --git a/src/Marten/ISessionFactory.cs b/src/Marten/ISessionFactory.cs index 6f94e324ea..cd04907828 100644 --- a/src/Marten/ISessionFactory.cs +++ b/src/Marten/ISessionFactory.cs @@ -43,9 +43,6 @@ public IDocumentSession OpenSession() { var documentSession = _store.OpenSession(BuildOptions()); - documentSession.CorrelationId = Activity.Current?.RootId; - documentSession.CausationId = Activity.Current?.ParentId; - ApplyMetadata(documentSession); return documentSession; }