Skip to content

Commit

Permalink
Merge pull request #14 from mxiamxia/fix-endpoint
Browse files Browse the repository at this point in the history
 read the collector endpoint from environment var if exists
  • Loading branch information
jj22ee authored Feb 12, 2024
2 parents 28d6723 + 7864082 commit 34e3603
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions SampleApp/src/Controller/AwsSdkInstrumentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
}
}

0 comments on commit 34e3603

Please sign in to comment.