From 786408284ca4c105b8c8255dd21c4763294acc9a Mon Sep 17 00:00:00 2001 From: Min Xia Date: Fri, 9 Feb 2024 13:50:08 -0800 Subject: [PATCH] read the collector endpoint from environment var if exists --- .../Controller/AwsSdkInstrumentationController.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SampleApp/src/Controller/AwsSdkInstrumentationController.php b/SampleApp/src/Controller/AwsSdkInstrumentationController.php index e7d44a6..8b8b0b7 100644 --- a/SampleApp/src/Controller/AwsSdkInstrumentationController.php +++ b/SampleApp/src/Controller/AwsSdkInstrumentationController.php @@ -68,7 +68,8 @@ public function outgoingHttpCall(): Response If running this sample app locally, set the endpoint to correspond to the endpoint of your collector instance. */ - $transport = (new GrpcTransportFactory())->create('http://otel:4317' . OtlpUtil::method(Signals::TRACE)); + $endpoint = $this->getEndpoint(); + $transport = (new GrpcTransportFactory())->create($endpoint . OtlpUtil::method(Signals::TRACE)); $exporter = new SpanExporter($transport); // Initialize Span Processor, X-Ray ID generator, Tracer Provider, and Propagator @@ -145,7 +146,8 @@ public function awsSdkCall(): Response If running this sample app locally, set the endpoint to correspond to the endpoint of your collector instance. */ - $transport = (new GrpcTransportFactory())->create('http://otel:4317' . OtlpUtil::method(Signals::TRACE)); + $endpoint = $this->getEndpoint(); + $transport = (new GrpcTransportFactory())->create($endpoint . OtlpUtil::method(Signals::TRACE)); $exporter = new SpanExporter($transport); // Initialize Span Processor, X-Ray ID generator, Tracer Provider, and Propagator @@ -215,4 +217,12 @@ public function awsSdkCall(): Response ['traceId' => $traceId] ); } + + private function getEndpoint(): string + { + if (Configuration::has(Variables::OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)) { + return Configuration::getString(Variables::OTEL_EXPORTER_OTLP_TRACES_ENDPOINT); + } + return 'http://0.0.0.0:4317'; + } } \ No newline at end of file