Skip to content

feat: support propagation of OpenTelemetry context from clients #568

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

pdecat
Copy link
Contributor

@pdecat pdecat commented Jun 18, 2025

This PR allows forwarding OpenTelemetry context from clients to Steampipe FDW.

From client perspective, it can be used like this (python with psycopg):

import logging

import psycopg

from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator

logger = logging.getLogger(__name__)

steampipe_conn = psycopg.connect(
    host="127.0.0.1",
    dbname="steampipe",
    user="steampipe",
    port="9193",
    password="steampipe",
    autocommit=True,
)

trace_context = {}
TraceContextTextMapPropagator().inject(trace_context)
if traceparent := trace_context.get("traceparent"):
    logger.debug("Propagating OpenTelemetry traceparent: %s", traceparent)
    steampipe_conn.execute(f"SET steampipe.traceparent = '{traceparent}'")

    if tracestate := trace_context.get("tracestate"):
        logger.debug("Propagating OpenTelemetry tracestate=%s", tracestate)
        steampipe_conn.execute(f"SET steampipe.tracestate = '{tracestate}'")

steampipe_conn.execute("SELECT account_id FROM aws_account")
steampipe_conn.execute("SELECT arn FROM aws_health_event")

When traces are ingested in an OpenTelemetry compatible solution such as Google Cloud Tracing, traces are properly grouped, e.g.:

image

@pdecat pdecat changed the title feat/otel context propagation from client feat: support propagation of OpenTelemetry context from clients Jun 18, 2025
@cbruno10 cbruno10 requested a review from Copilot June 18, 2025 13:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables the propagation of OpenTelemetry context from clients to Steampipe FDW by extracting and forwarding tracing information.

  • Adds new functions and tests to parse and propagate trace context in hub and FDW layers.
  • Updates function signatures and logging for better trace context handling and debugging.
  • Integrates trace context extraction from PostgreSQL session variables into the FDW plan state.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
types/pathkeys_test.go Removed an unnecessary blank line.
hub/trace_context_test.go Introduced tests for tracing context parsing and verification.
hub/scan_iterator_base.go Added debug logging for creating and validating trace carriers.
hub/hub_remote.go & hub/hub_local.go Updated trace context function calls to incorporate new options.
hub/hub_base.go Modified trace context propagation and parsing, with improved logging.
fdw/fdw_helpers.h, fdw/fdw.c, fdw/common.h, fdw.go Added functions to extract and integrate trace context from session variables.
Comments suppressed due to low confidence (1)

hub/hub_base.go:434

  • The 'strings' package is used in parseTraceContext but is not imported. Please add "import "strings"" to the import block.
	parts := strings.Split(traceContextString, ";")

@misraved misraved requested review from kaidaguerre and pskrbasu June 18, 2025 14:06
@@ -9,8 +9,6 @@ package main
#include "nodes/pg_list.h"
#include "utils/timestamp.h"

static Name deserializeDeparsedSortListCell(ListCell *lc);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also done separately in #567

*/
static char *extractTraceContextFromSession(void)
{
const char *traceparent = GetConfigOption("steampipe.traceparent", true, false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to fix indentation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant