Skip to content

[Hackathon] otel-instrumentation#5273

Draft
supersven wants to merge 14 commits into
developfrom
sventennie/otel
Draft

[Hackathon] otel-instrumentation#5273
supersven wants to merge 14 commits into
developfrom
sventennie/otel

Conversation

@supersven

Copy link
Copy Markdown
Contributor

Checklist

  • Add a new entry in an appropriate subdirectory of changelog.d
  • Read and follow the PR guidelines

@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Jun 17, 2026
sghosh23 and others added 7 commits June 17, 2026 18:51
Attaches only to the top-level (request) span for now.
- Cassandra: Wrap all Client queries in 'cassandra.query' spans via runClientTraced
  - Implemented in libs/cassandra-util/src/Cassandra/Exec.hs
  - Integrated into brig, galley, cannon services
  - Uses global tracer provider; spans include full query timing

- PostgreSQL: Add tracing for critical ConversationStore operations
  - Implemented runStatementTraced wrapper in libs/wire-subsystems/src/Wire/Postgres.hs
  - Instrumented 4 operations: delete_conversation, get_team_conversation,
    get_team_conversations, delete_team_conversations
  - Query names used as span identifiers (e.g., db.query.get_team_conversations)

- All services now emit OpenTelemetry spans for database operations
- Spans export to Grafana Tempo for distributed tracing and performance analysis
@sghosh23 sghosh23 changed the title Sventennie/otel [Hackathon] otel-instrumentation Jun 18, 2026
Comment on lines +182 to +213
runClientTraced :: ClientState -> Client a -> IO a
runClientTraced st action = do
tp <- getGlobalTracerProvider
let tracer = makeTracer tp "cassandra" tracerOptions
inSpan tracer "cassandra.query" defaultSpanArguments $ runClient st action

cqlSpanArgs :: PrepQuery k a b -> SpanArguments
cqlSpanArgs q =
let QueryString cql = queryString q
in defaultSpanArguments
{ attributes = HashMap.fromList [("db.statement", toAttribute (LT.toStrict cql))] }

-- | Like 'query' but adds a 'db.statement' OTel span attribute with the CQL template.
queryTraced :: (MonadClient m, Tuple a, Tuple b) => PrepQuery R a b -> QueryParams a -> m [b]
queryTraced q p = liftClient $ do
tp <- liftIO getGlobalTracerProvider
let tracer = makeTracer tp "cassandra" tracerOptions
inSpan tracer "cassandra.query" (cqlSpanArgs q) $ query q p

-- | Like 'query1' but adds a 'db.statement' OTel span attribute with the CQL template.
query1Traced :: (MonadClient m, Tuple a, Tuple b) => PrepQuery R a b -> QueryParams a -> m (Maybe b)
query1Traced q p = liftClient $ do
tp <- liftIO getGlobalTracerProvider
let tracer = makeTracer tp "cassandra" tracerOptions
inSpan tracer "cassandra.query" (cqlSpanArgs q) $ query1 q p

-- | Like 'write' but adds a 'db.statement' OTel span attribute with the CQL template.
writeTraced :: (MonadClient m, Tuple a) => PrepQuery W a () -> QueryParams a -> m ()
writeTraced q p = liftClient $ do
tp <- liftIO getGlobalTracerProvider
let tracer = makeTracer tp "cassandra" tracerOptions
inSpan tracer "cassandra.query" (cqlSpanArgs q) $ write q p

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of ...Traced variants of these functions, it'd be nice to default to the Traced variants, so rest of the code doesn't have to choose between calling query1 and query1Traced, the queries should always be traced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants