Skip to content

Traces and Spans not updated in the SDK #53

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

Closed
the-praxs opened this issue Mar 12, 2025 · 3 comments · Fixed by #55
Closed

Traces and Spans not updated in the SDK #53

the-praxs opened this issue Mar 12, 2025 · 3 comments · Fixed by #55

Comments

@the-praxs
Copy link
Contributor

Issue

In the export method in processor.py the following code lines do not update the traces and spans variables -

traces: list[dict[str, Any]] = []
spans: list[dict[str, Any]] = []

data = [item.export() for item in items if item.export()]
payload = {"data": data}

headers = {
    "Authorization": f"Bearer {self.api_key}",
    "Content-Type": "application/json",
    "OpenAI-Beta": "traces=v1",
}

Hence, in the debug logs you won't see the correct values when this code is run -

# Exponential backoff loop
attempt = 0
delay = self.base_delay
while True:
    attempt += 1
    try:
        response = self._client.post(url=self.endpoint, headers=headers, json=payload)

        # If the response is successful, break out of the loop
        if response.status_code < 300:
            logger.debug(f"Exported {len(traces)} traces, {len(spans)} spans")
            return

Solution

Updating the above code snippet with the following solves the issue -

traces: list[dict[str, Any]] = []
spans: list[dict[str, Any]] = []

# Categorize items into traces and spans
for item in items:
    if hasattr(item, 'export') and callable(item.export):
        export_data = item.export()
        if export_data:
            if isinstance(item, Trace):
                traces.append(export_data)
            else:
                spans.append(export_data)

data = traces + spans
payload = {"data": data}
@rm-openai
Copy link
Collaborator

you're totally right. I think it might be better to just log the total number of spans+logs instead of doing this isinstance. Feel free to make a PR, or I can do so later.

@the-praxs
Copy link
Contributor Author

you're totally right. I think it might be better to just log the total number of spans+logs instead of doing this isinstance. Feel free to make a PR, or I can do so later.

Creating a PR asap!

@the-praxs
Copy link
Contributor Author

#55 resolves this

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 a pull request may close this issue.

2 participants