open-telemetry / opentelemetry-php

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

Steps to send php application traces to Otel collector #345

Closed anilreddydonthireddy closed 2 years ago

anilreddydonthireddy commented 3 years ago

Hi,

I have PHP and composer installed on my windows. The versions installed are as below

C:\Users\XXX>php --version PHP 8.0.6 (cli) (built: May 4 2021 23:31:41) ( NTS Visual C++ 2019 x64 ) Copyright (c) The PHP Group Zend Engine v4.0.6, Copyright (c) Zend Technologies

C:\Users\XXX>composer --version Composer version 2.0.14 2021-05-21 17:03:37

Now when I go to opentelemetry-php folder which is cloned from git project and run composer step to add open-telemetry/opentelemetry. I am getting as below

C:\Users\XXX\Documents\GitWorkspace\opentelemetry-php>composer require open-telemetry/opentelemetry Using version ^0.0.2 for open-telemetry/opentelemetry Root package 'open-telemetry/opentelemetry' cannot require itself in its composer.json

Now, I would like to know what steps I need to do to run the php example to collect traces and send them to my otel collector which is configured on another machine.

Please help me with the steps I need to do to start the example and collect traces.

Thanking you. Anil.

prondubuisi commented 3 years ago

Hello @anilreddydonthireddy , I tried to replicate this issue locally

(base) Ndubuisis-MacBook-Pro:open-php prondubuisi$ composer require open-telemetry/opentelemetry
Using version ^0.0.2 for open-telemetry/opentelemetry
Root package 'open-telemetry/opentelemetry' cannot require itself in its composer.json
(base) Ndubuisis-MacBook-Pro:open-php prondubuisi$ git remote -v
origin  https://github.com/open-telemetry/opentelemetry-php (fetch)
origin  https://github.com/open-telemetry/opentelemetry-php (push)
prondubuisi https://github.com/prondubuisi/opentelemetry-php (fetch)
prondubuisi https://github.com/prondubuisi/opentelemetry-php (push)
(base) Ndubuisis-MacBook-Pro:open-php prondubuisi$ 

It appears you are trying to require this package, within itself, hence the error. You should instead require the package within the Project you are trying to export traces from.

Here are some examples on how to instrument your PHP application using this package, here, here

I hope this helps.

anilreddydonthireddy commented 3 years ago

@prondubuisi Thanks a lot for your reply. the links provided are helpful to understand the integration.

In my requirement I want to write traces logs to open telemetry collector as I have collector writing to my required database.

Is there any example that helps to write the trace logs of php application to open telemetry collector.

prondubuisi commented 3 years ago

Great! @anilreddydonthireddy, I don't have much experience with Collectors, but I am sure @bobstrecansky can pitch in

bobstrecansky commented 3 years ago

We don't have any explicit documentation on writing to the collector, as that capability is relatively new to our project. You should be able to use the OTLP GRPC example to give you a general idea of how to write to the collector. If that isn't clear enough, we will be happy to continue troubleshooting with you!

anilreddydonthireddy commented 3 years ago

@bobstrecansky thanks a lot for your response.

I have gone through the example code shared above. It looks good. I could not understand where can I configure the otel collector address in the code. I need to point application to write traces to remote otel collector (for example: http://:55680.

@bobstrecansky Please help me to configure the otel collector url.

Thanks, Anil.

bobstrecansky commented 3 years ago

@anilreddydonthireddy - you should be able to use an environment variable to set the value of the collector:

https://github.com/open-telemetry/opentelemetry-php/blob/main/contrib/OtlpGrpc/Exporter.php#L82

In your example, you'd probably want to set OTEL_EXPORTER_OTLP_ENDPOINT to http://:55680

bobstrecansky commented 3 years ago

@anilreddydonthireddy - did this solve your issue?

anilreddydonthireddy commented 3 years ago

@bobstrecansky I created new php project and installed open-telemetry package to the project. When I run the above example as below, I am getting below error


php -f AlwaysOnOTLPGrpcExample1.php PHP Fatal error: Uncaught Error: Class "grpc\ChannelCredentials" not found in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\OtlpGrpc\Exporter.php:108 Stack trace:

0 C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\examples\AlwaysOnOTLPGrpcExample1.php(24): OpenTelemetry\Contrib\OtlpGrpc\Exporter->__construct()

1 {main}

thrown in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\OtlpGrpc\Exporter.php on line 108

Fatal error: Uncaught Error: Class "grpc\ChannelCredentials" not found in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\OtlpGrpc\Exporter.php:108 Stack trace:

0 C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\examples\AlwaysOnOTLPGrpcExample1.php(24): OpenTelemetry\Contrib\OtlpGrpc\Exporter->__construct()

1 {main}

thrown in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\OtlpGrpc\Exporter.php on line 108


When I try to run AlwaysOnOTLPExample.php, I am getting few arguments error for exports.


php -f AlwaysOnOTLPExample.php PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function OpenTelemetry\Contrib\Otlp\Exporter::__construct(), 1 passed in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\examples\AlwaysOnOTLPExample.php on line 24 and at least 4 expected in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\Otlp\Exporter.php:81 Stack trace:

0 C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\examples\AlwaysOnOTLPExample.php(24): OpenTelemetry\Contrib\Otlp\Exporter->__construct('PHP - OTLP Exam...')

1 {main}

thrown in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\Otlp\Exporter.php on line 81

Fatal error: Uncaught ArgumentCountError: Too few arguments to function OpenTelemetry\Contrib\Otlp\Exporter::__construct(), 1 passed in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\examples\AlwaysOnOTLPExample.php on line 24 and at least 4 expected in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\Otlp\Exporter.php:81 Stack trace:

0 C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\examples\AlwaysOnOTLPExample.php(24): OpenTelemetry\Contrib\Otlp\Exporter->__construct('PHP - OTLP Exam...')

1 {main}

thrown in C:\Users\anil.donthireddy.BDELYSIUM\Documents\GitWorkspace\TestPHPAnil\vendor\open-telemetry\opentelemetry\contrib\Otlp\Exporter.php on line 81


what are the other arguments that needs to be provided while instantiating the Exporter from example code ?

bobstrecansky commented 3 years ago

The constructor you are getting an error for lives here: https://github.com/open-telemetry/opentelemetry-php/blob/main/contrib/Otlp/Exporter.php#L81

Are you passing any other values? If you could share some example code I might be able to understand where things are going awry.

anilreddydonthireddy commented 3 years ago

@bobstrecansky I am using the example code AlwaysOnOTLPExample.php

bobstrecansky commented 3 years ago

I'm conferring with the other people who created this; will get back to you as son as I hear back.

anilreddydonthireddy commented 3 years ago

Thanks @bobstrecansky

I tried below and see the logs in terminal showing exporting the traces, but the records are not being pushed to my otel collector.

I see the env variable OTEL_EXPORTER_OTLP_ENDPOINT set to my otel collector address.


C:\Users\xxxxxx\Documents\GitWorkspace\opentelemetry-php\examples>php -debug -f AlwaysOnOTLPExample.php Starting OTLPExample Exporting Trace: 33d430ad918a72b38651bef022b1cba5, Parent: None, Span: 73b09e02ef6609d5 Exporting Trace: 75fcfa105ee209f498dff6025fe258c9, Parent: None, Span: 7040369aa0cb5c5e Exporting Trace: 79e21ce84cecf3b4f8a211fc67836955, Parent: None, Span: 6cc76c3750fdc963 Exporting Trace: ed5a24e2108a30b9a508b958e6d3fea2, Parent: None, Span: 6026c668112b20e6 Exporting Trace: 2776b8508585c9ca274ffb756598794e, Parent: None, Span: 92f8065b56623254 OTLPExample complete!


I can not see more logs to check if exporter is failing to send the traces to otel collector. Is there a way to check it?

anilreddydonthireddy commented 3 years ago

@bobstrecansky

Can I get some help to figure out why the trace logs are not logging to otel collector

codeboten commented 3 years ago

The constructor you are getting an error for lives here: https://github.com/open-telemetry/opentelemetry-php/blob/main/contrib/Otlp/Exporter.php#L81

Are you passing any other values? If you could share some example code I might be able to understand where things are going awry.

I was running into this issue as well with the OtlpGrpc exporter. I ended up needing to install the grpc extension for php and running the code with the php -d extension=grpc.so

bobstrecansky commented 3 years ago

@anilreddydonthireddy - Did @codeboten's response help you?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not had recent activity, but it can be reopened. Thank you for your contributions.