PostHog / posthog-node

Official PostHog Node library
MIT License
21 stars 19 forks source link

feat: add distributed tracing support to `posthog-node`-package #35

Closed weyert closed 2 years ago

weyert commented 3 years ago

Changes

Introduces support for distributed tracing to allow adding trace span for the isFeatureEnabled-call to see all the fature flag calls in e.g. network requests

Checklist

yakkomajuri commented 3 years ago

Hey @weyert ! Thanks for this!

Any chance you could remove the linting changes?

weyert commented 3 years ago

Sure, I ran format-script on the project

weyert commented 3 years ago

@yakkomajuri okay, i have reverted the formatting changes and wrote a unit test to ensure the span gets created

mariusandra commented 3 years ago

Hey, what's opentelemetry and is it worth a tight integration between it and posthog-node? Asking from a genuine place of curiosity, as I'm not familiar with this space of tools, having only used statsd in other posthog project, and new relic in a previous company.

Asking also since I see you incresed the bundled size limit by 90kb, even though the dependency isn't that big...

weyert commented 3 years ago

Opentelemetry is a new standard for distributed tracing, metrics, logging, and allows you to export them to a wide variety of solutions, e.g. Google Trace, Github [1], Lightstep, New Relice [2], Microsoft (partish of Dotnet itself). All the major companies ware collaborating to define this new standard/specification. The tracing has been 1.0.0 for a while now, and recently the API specification for metrics has been stabilised too and now hardly at work speccing out the SDK and prototyping the SDK for the major programming languages (e.g. python, dotnet).

New Relic supports the standard too, see [2]. I am trying to help with the opentelemetry-js-packges myself but they have a python package [3] to with apparently ready available instrumentation.

I am suggesting this PR so it makes it easy for people using this solution to easily at which times the feature flags calls are made as part of a request as they become part of a trace. We at work have been using it for a while now and are quit happy with the solution. I am also happy to see that other companies like Doordash, Zalondo are using it too :)

I will have a closer look at why the increase size in bundle size occurred 🤓 I prefer this approach then going to troublesome monkey patching approach with shimmer / require-in-the-middle.

[1] https://github.blog/2021-05-26-why-and-how-github-is-adopting-opentelemetry/ [2] https://docs.newrelic.com/docs/integrations/open-source-telemetry-integrations/opentelemetry/introduction-opentelemetry-new-relic/ [3] https://github.com/open-telemetry/opentelemetry-python-contrib [4] https://devblogs.microsoft.com/dotnet/opentelemetry-net-reaches-v1-0/

weyert commented 2 years ago

Closing ticket as I have achieved the same by using OpenFeature (www.openfeature.dev) and its hooks support