open-telemetry / opentelemetry-php

The OpenTelemetry PHP Library
https://opentelemetry.io/docs/instrumentation/php/
Apache License 2.0
751 stars 186 forks source link

Stackdriver Exporter #577

Closed enumag closed 2 years ago

enumag commented 2 years ago

I'd like to use OpenTelemetry PHP and connect it to https://cloud.google.com/trace.

It seems that an exporter for Stackdriver doesn't exist yet and couldn't find an issue for it either.

How difficult do you think it would be?

tidal commented 2 years ago

It seems that an exporter for Stackdriver doesn't exist yet and couldn't find an issue for it either.

No there is neither an exporter for Stackdriver nor an issue yet. We are still in the process of getting the library stable and in line with the spec, so that's where our main focus is at the moment. However feel free to create a feature request for whatever you think would be a worthwhile addition. There is a lot of stuff missing at the moment.

How difficult do you think it would be?

I am not familiar with the specifics of Stackdriver/Google Cloud Trace, but from taking a brief look at the documentation, it doesn't look too complicated. The main part would be to create a SpanConverter which translates Otel Span into the Google format. From what I have seen there is a Stackdriver Client library, which could be leveraged. The downside is, that it uses google/cloud-core which has a hard dependency on Guzzle for HTTP requests, which we try to avoid, but I guess that would be ok for a contrib exporter.

Anyway in general such an eporter would go into the opentelemetry-php-contrib repository.

bobstrecansky commented 2 years ago

You can also perform this action with our current state by posting to the OpenTelemetry collector and having the collector communicate with Google Cloud Trace. I'm very familiar with this setup and have used something similar in a production environment. Happy to answer other questions.

enumag commented 2 years ago

@bobstrecansky Can you share some details how to make the collector communicate with cloud trace? I couldn't find any mention of Stackdriver or GCP or anything related in the docs.

bobstrecansky commented 2 years ago

Stackdriver is no longer called stackdriver, it's called Google Cloud Trace. Here is the documentation that I used to formulate my collector config. We use a zipkin receiver, but you should be able to use any of the receivers. Here is my example config.yaml that you could reference:

https://gist.github.com/bobstrecansky/212ba22cdb743d2e22a752dc4783efa0

enumag commented 2 years ago

@bobstrecansky What I'm confused about is how does the collector authenticate to Google Cloud to be able to send data there? Your example doesn't have any place where some authentication token would go...

bobstrecansky commented 2 years ago

Oh! You must create a service account in GCP with the proper permissions. You can generate credentials in JSON format, and reference this JSON file in the GOOGLE_APPLICATION_CREDENTIALS environment variable for authentication.

bobstrecansky commented 2 years ago

Documentation for this can be found here: https://cloud.google.com/docs/authentication/getting-started

enumag commented 2 years ago

Ah so basically the collector just requires the GOOGLE_APPLICATION_CREDENTIALS env var and it will work. Alright, that sounds cool!

bobstrecansky commented 2 years ago

@enumag - I'm going to close this because I think we've resolved all your issues. Feel free to reopen if needed.