Skip to content

Commit e008230

Browse files
authored
Fix environment for browser traces (#25)
1 parent a6b35cf commit e008230

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

backend/api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ async def game_move(db: Annotated[DB, Depends(DB.get_dep)], game_id: UUID4, colu
9494
async def client_traces(request: Request):
9595
httpx_client: httpx.AsyncClient = request.app.state.httpx_client
9696

97-
response = await httpx_client.post('v1/traces', json=await request.json())
98-
if not response.is_success:
99-
logfire.warn('prox failed {status=}', status=response.status_code, response=response.text)
97+
with logfire.suppress_instrumentation():
98+
response = await httpx_client.post('v1/traces', json=await request.json())
99+
if not response.is_success:
100+
logfire.warn('prox failed {status=}', status=response.status_code, response=response.text)
100101

101102
return {
102103
'status_code': response.status_code,

backend/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def lifespan(app: fastapi.FastAPI):
4747

4848

4949
app = fastapi.FastAPI(lifespan=lifespan)
50-
logfire.instrument_fastapi(app, capture_headers=True)
50+
logfire.instrument_fastapi(app, capture_headers=True, excluded_urls=['client-traces'])
5151
logfire.instrument_pydantic_ai()
5252
logfire.instrument_asyncpg()
5353
logfire.instrument_httpx(capture_all=True)

frontend/src/Instrumentation.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const ClientInstrumentationProvider: Component<ClientInstrumentationProvi
1515
logfire.configure({
1616
traceUrl: url.toString(),
1717
serviceName: 'frontend',
18+
environment: import.meta.env.MODE === 'development' ? 'dev' : 'prod',
1819
serviceVersion: '0.1.0',
1920
// for development purposes, we want to see traces as soon as they happen, so maxExportBatchSize is set to 1.
2021
// in production, we want to batch traces and send them in batches
@@ -25,6 +26,7 @@ export const ClientInstrumentationProvider: Component<ClientInstrumentationProvi
2526
getWebAutoInstrumentations({
2627
'@opentelemetry/instrumentation-fetch': {
2728
propagateTraceHeaderCorsUrls: /.*/,
29+
ignoreNetworkEvents: true,
2830
},
2931
// disable user interaction instrumentation, clicks are not relevant for us
3032
'@opentelemetry/instrumentation-user-interaction': {

0 commit comments

Comments
 (0)