aspire-samples icon indicating copy to clipboard operation
aspire-samples copied to clipboard

Add sample that send telemetry from the browser

Open JamesNK opened this issue 1 year ago • 10 comments

See https://github.com/dotnet/aspire/tree/main/playground/BrowserTelemetry as an example of how to do this.

JamesNK avatar Aug 14 '24 06:08 JamesNK

I'm thinking we should just update the existing AspireWithJavaScript sample to do this. It has Angular, React, and Vue apps in it so seems like a good candidate to add this functionality.

/Cc @IEvangelist

DamianEdwards avatar Nov 07 '24 22:11 DamianEdwards

I'm thinking we should just update the existing AspireWithJavaScript sample to do this. It has Angular, React, and Vue apps in it so seems like a good candidate to add this functionality.

/Cc @IEvangelist

Tried doing this, only to learn that it's not really well supported. I spoke with @vhvb1989 and @davidfowl on this, and here's the conclusion as to why we cannot do this with the AspireWithJavaScript sample:

  • Since these apps are SPAs, they're built in the container and their bits are pushed to a /dist folder and served by nginx as static files.

  • In order to get the values of the OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, and OTEL_RESOURCE_ATTRIBUTES at deployment time, I attempted to use the PublishAsDockerFile with the following build args:

    DockerBuildArg[] otelBuildArgs = [
        new("OTEL_EXPORTER_OTLP_ENDPOINT"),
        new("OTEL_EXPORTER_OTLP_HEADERS"),
        new("OTEL_RESOURCE_ATTRIBUTES")
    ];
    

    However, these env vars are not available during build when publishing the app.

  • At runtime, these env var values are available, but at that point - it's too late.

  • Also, ACA doesn't expose the OTEL collector.

IEvangelist avatar Nov 13 '24 17:11 IEvangelist

@IEvangelist everything you're referring to is regarding supporting this after publishing to ACA, correct? IIUC we could make the sample support it at dev time without much trouble but it wouldn't work after publishing, right?

DamianEdwards avatar Nov 14 '24 17:11 DamianEdwards

@IEvangelist everything you're referring to is regarding supporting this after publishing to ACA, correct? IIUC we could make the sample support it at dev time without much trouble but it wouldn't work after publishing, right?

@DamianEdwards - Correct, I have it working locally for dev time support...that was still a bit of work though. So many different opinions about how each JS SPA framework handles building env vars.

IEvangelist avatar Nov 14 '24 18:11 IEvangelist

OK. I guess we just need to decide if we want to include it in the sample in that state then, perhaps with a note in the README. Given how many folks asked for the feature and the fact we made changes to unblock it, seems like it's worthwhile?

DamianEdwards avatar Nov 14 '24 20:11 DamianEdwards

Yeah, again I have this all working locally and correctly reporting browser telemetry for each SPA. I could add a note in the README.md to say something about the deployment not working. Perhaps, we should remove the Dockerfiles from the sample then too, as it's really confusing to include them since they will not work.

IEvangelist avatar Nov 22 '24 00:11 IEvangelist

Could we update the sample logic so that the client app gets the URL via a call to a backend API?

DamianEdwards avatar Dec 02 '24 18:12 DamianEdwards

Hi all, I am trying to implement this for an aspire app using Vite as the SPA bundler. I am also in the same situation where OTEL from the browser is working in dev, but I cannot get it working on my deployment ACA.

@IEvangelist you mentioned that:

  • Also, ACA doesn't expose the OTEL collector.

Would this mean that there is no way currently to get OTEL from the browser when deploying to ACA? Thanks!

ethangillengg avatar Feb 12 '25 19:02 ethangillengg

Any update on this? There is no point in having samples with javascript if it doesn't work, why even bother having it then?

unmade-spangle avatar Apr 24 '25 15:04 unmade-spangle

Would it make sense to add a request sample to the API service also? Open Telemetry + requests from the frontend to the backend? I was checking the repo to figure out how to expose the API port so I could inject it on the frontend as base url for HTTP requests.

gusflopes avatar May 23 '25 16:05 gusflopes