-
Notifications
You must be signed in to change notification settings - Fork 70
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
Console instrumentation ignore span context when calling pushLog #632
Comments
Ok, so I miss read the code it falls back on calling the But if I debug it in the browser the But the console.log is called inside an active span: Any ideas what I'm missing @codecapitano ? |
Hi @mxab I tested it in the Faro demo. |
@mxab When and were do you initialize Faro? Maybe you can share your Faro config? |
getSpanConext is fetching the context with this line of code: If there's no active span it returns undefined because it can't find an active context. |
Hmm the But the returned base context seems to be empty, there fore not finding any span context. The general init is an angular application import { ErrorHandler, NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { ReactiveFormsModule } from '@angular/forms';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { FaroErrorHandler } from './errors';
import { getWebInstrumentations, initializeFaro, createSession, faro } from '@grafana/faro-web-sdk';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';
import { NavigationStart, Router } from '@angular/router';
import { filter, map } from 'rxjs';
function initFaro(router: Router): Function {
return async () => {
initializeFaro({ // <---------------------------------------------------------INIT FARO
url: 'http://localhost:12347/collect',
apiKey: 'secret',
app: {
name: 'my-angular-app',
version: '1.0.0',
environment: 'development'
},
sessionTracking: {
enabled: true,
session: createSession({
}),
},
instrumentations: [...getWebInstrumentations(), new TracingInstrumentation(
{
instrumentationOptions: {
// Requests to these URLs will have tracing headers attached.
propagateTraceHeaderCorsUrls: [new RegExp('http://localhost:8080/*'), new RegExp('http://localhost:8000/*')],
},
}
)],
});
// --------------------------------------------- end init
// ---------------------------------------------- configure faro view setting
router.events.pipe(
filter(e => e instanceof NavigationStart),
map(e => e as NavigationStart))
.subscribe((e: NavigationStart) => {
faro.api.setView({
name: e.url
})
})
//---------------------------------------------- end faro view
}
}
@NgModule({
declarations: [
AppComponent,
HomeComponent
],
bootstrap: [AppComponent],
imports: [BrowserModule, ReactiveFormsModule, AppRoutingModule],
providers: [
{ provide: APP_INITIALIZER, useFactory: initFaro, multi: true, deps: [Router] }, // <------------------ faro init via APP_INITIALIZER
{ provide: ErrorHandler, useClass: FaroErrorHandler },
provideHttpClient(withInterceptorsFromDi())
]
})
export class AppModule { }
```
I have another application which uses 1.6.0 where it works. The setup looks similar. Investigating more.... |
Thank you so much Max 🙏 Hmm ok, with 1.8.0 we update the otel dependencies in the web-tracing and Faro core packages. Cheers |
Maybe an idea: Maybe it happens that it gets called multiple times and overwrites the context with |
I downgraded to 1.6.0 but the issue remain. I noticed when I the console.info inside the The span it self has a value of a {
"_spanContext": {
"traceId": "00000000000000000000000000000000",
"spanId": "0000000000000000",
"traceFlags": 0
}
} faro.api
.getOTEL()
?.trace.getTracer('frontend')
.startActiveSpan('hello world', (span) => {
// send a log message
console.info("sending hello to backend")
const request$ = this.http.get<{message: string, id: number}>(backend, {
params: {
name
}
});
lastValueFrom(request$).then((res) => {
console.info("got response from backend ", res.message)
this.results.push(res);
}).finally(() => {
span.end();
});
});
|
Did you already try the otel logger? Right before calling the Faro init function you can enable otel logging.
And you can also enable Faro debug logs
|
Sorry for the late response, somehow I missed that message. |
You should see them in the browsers console, no? |
Hi @codecapitano sorry for responding so late, I got dragged into other issues and hey suddenly its half a year later :D It looks like the issue is resolved with a newer version of faro. Any ways thank you for your support on that issue! |
Hey @mxab no worries at all and many thanks for the update :) Thanks for opening the issue and making Faro better. Cheers |
Description
When using e.g.
console.info(...
inside an active span the instrumented console doesn't provide the span context to the pushLogs callfaro-web-sdk/packages/web-sdk/src/instrumentations/console/instrumentation.ts
Line 24 in 3f20032
If this is missing the pushLog doesn't attach tracing infos to the log statment
faro-web-sdk/packages/core/src/api/logs/initialize.ts
Line 36 in 3f20032
Steps to reproduce
Expected behavior
When using console.info inside a active span the logs should have trace data
Actual behavior
No trace / span data inside the logs on the faro side for
kind=log
log entriesEnvironment
The text was updated successfully, but these errors were encountered: