Skip to content

Make starting transactions from headers more convenient #1384

@ueman

Description

@ueman

Problem Statement

It's currently quite cumbersome to start transactions from headers on the backend.
See the following example:

final request = ...
final urlDetails = HttpSanitizer.sanitizeUrl(request.url.toString());

var description = request.method.toString();

if (urlDetails != null) {
  description += ' ${urlDetails.urlOrFallback}';
}

final traceHeaderValue = request.headers['sentry-trace'];
final baggageHeaderValue = request.headers['baggage'];

SentryTransactionContext? trxContext;

if (traceHeaderValue != null) {
  trxContext = SentryTransactionContext.fromSentryTrace(
    description,
    'http.client',
    SentryTraceHeader.fromTraceHeader(traceHeaderValue),
    baggage: baggageHeaderValue != null
        ? SentryBaggage.fromHeader(baggageHeaderValue)
        : null,
  );
}

final trx = trxContext != null
  ? Sentry.startTransactionWithContext(trxContext, bindToScope: true)
  : Sentry.startTransaction(description, 'http.client', bindToScope: true);

Solution Brainstorm

It would be very convenient if I can either create a SentryTransactionContext from headers, or start a transaction directly from headers with something like Sentry.startTransactionFromHeaders.

I recognize that it's probably tricky to choose what to except as cookies, since dart:io, http and dio use different formats for their headers.

Are you willing to submit a PR?

None

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions