Skip to content

feat: add current span enrichment helpers - #19

Merged
shreyas-n-harness merged 2 commits into
mainfrom
feat/current-span-enrichment
Jul 27, 2026
Merged

feat: add current span enrichment helpers#19
shreyas-n-harness merged 2 commits into
mainfrom
feat/current-span-enrichment

Conversation

@shreyas-n-harness

@shreyas-n-harness shreyas-n-harness commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Currently there is no way in which users can ingest custom data (with custom labels), this PR adds a way to ingest per span attribute

Usecases

  • CACM users adding tenant data per trace
  • Agent action resolved per trace. Example: created, updated, deleted, no_action

Changes

  • Add set_span_attribute() and set_span_attributes() public APIs.
  • Enrich only the active recording span.
  • Preserve native OpenTelemetry attribute types.
  • No baggage, child-span inheritance, or downstream propagation.
  • Document usage, timing, precedence, and sampling constraints.
  • Add focused unit tests.

Usage

from google import genai
from opentelemetry import trace

from harness_sdk import set_span_attributes

client = genai.Client(
    vertexai=True,
    project="my-gcp-project",
    location="us-central1",
)

tracer = trace.get_tracer(__name__)


def generate_answer(tenant_id: str, prompt: str) -> str:
    with tracer.start_as_current_span("tenant.vertex.request"):
        set_span_attributes({
            "tenant.id": tenant_id,
            "agent.action.type": "generate-answer",
        })

        response = client.models.generate_content(
            model="gemini-2.5-flash",
            contents=prompt,
        )

        return response.text

Expose a stable SDK facade for enriching active spans without leaking internal instrumentation or propagating customer attributes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Drop plan and design docs no longer needed in the repo.

Co-authored-by: Cursor <cursoragent@cursor.com>
@shreyas-n-harness
shreyas-n-harness merged commit e19db10 into main Jul 27, 2026
7 checks passed
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.

3 participants