Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting service name from auto instrumentation context #881

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

pdelewski
Copy link
Member

Currently there is no way to set service name from auto instrumentation context for zipkin and newrelic exporters.
We should read that from OTEL_SERVICE_NAME or any other configuration settings IMO.

@pdelewski pdelewski requested a review from a team as a code owner December 3, 2022 22:06
@codecov
Copy link

codecov bot commented Dec 3, 2022

Codecov Report

Merging #881 (c3b81ec) into main (02d9421) will increase coverage by 0.01%.
The diff coverage is 87.50%.

❗ Current head c3b81ec differs from pull request most recent head 31d358a. Consider uploading reports for the commit 31d358a to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #881      +/-   ##
============================================
+ Coverage     81.58%   81.59%   +0.01%     
  Complexity     2010     2010              
============================================
  Files           264      264              
  Lines          5223     5226       +3     
============================================
+ Hits           4261     4264       +3     
  Misses          962      962              
Flag Coverage Δ
7.4 81.07% <86.95%> (+<0.01%) ⬆️
8.0 81.57% <87.50%> (+0.01%) ⬆️
8.1 81.71% <87.50%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Contrib/Jaeger/HttpCollectorExporter.php 100.00% <ø> (ø)
src/Contrib/Newrelic/SpanExporterFactory.php 0.00% <0.00%> (ø)
src/Contrib/Zipkin/SpanExporterFactory.php 0.00% <0.00%> (ø)
src/Contrib/ZipkinToNewrelic/Exporter.php 85.00% <50.00%> (ø)
src/Contrib/Jaeger/AgentExporter.php 100.00% <100.00%> (ø)
src/Contrib/Jaeger/HttpSender.php 100.00% <100.00%> (ø)
src/Contrib/Newrelic/Exporter.php 100.00% <100.00%> (ø)
src/Contrib/Newrelic/SpanConverter.php 96.29% <100.00%> (+0.14%) ⬆️
src/Contrib/Zipkin/Exporter.php 100.00% <100.00%> (ø)
src/Contrib/Zipkin/SpanConverter.php 96.29% <100.00%> (+0.03%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02d9421...31d358a. Read the comment docs.

@Nevay
Copy link
Contributor

Nevay commented Dec 3, 2022

IMO the service name should not be a constructor argument and should be read in ::export() from SpanDataInterface::getResource() instead.

@pdelewski
Copy link
Member Author

IMO the service name should not be a constructor argument and should be read in ::export() from SpanDataInterface::getResource() instead.

Thx. That's the discussion I wanted to start opening this PR

@brettmc
Copy link
Collaborator

brettmc commented Dec 4, 2022

I think the spec agrees with Nevay here; the objective of providing the name in the exporter is eventually to pass it through as a service name, but that should indeed come from a resource attribute: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service
Since not all exporters accept a name, it looks like we should remove the constructor argument totally (assuming we can instead get the service name out of resource attributes)

@pdelewski
Copy link
Member Author

pdelewski commented Dec 5, 2022

IMO the service name should not be a constructor argument and should be read in ::export() from SpanDataInterface::getResource() instead.

@Nevay I'm currently looking into this code and have some concerns. export takes whole batch

public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface

its execution leads to execution of private function convertSpan(SpanDataInterface $span): array.

Should not we read and update service.name here?

@Nevay
Copy link
Contributor

Nevay commented Dec 5, 2022

Yes,

'serviceName' => $this->serviceName,
should be changed to something like

'serviceName' => $span->getResource()->getAttributes()->get(ResourceAttributes::SERVICE_NAME),

@pdelewski
Copy link
Member Author

Yes,

'serviceName' => $this->serviceName,

should be changed to something like

'serviceName' => $span->getResource()->getAttributes()->get(ResourceAttributes::SERVICE_NAME),

Thx. That's exactly what I was thinking about

@pdelewski pdelewski changed the title allow setting service name from auto instrumentation context WIP: allow setting service name from auto instrumentation context Dec 5, 2022
@pdelewski pdelewski changed the title WIP: allow setting service name from auto instrumentation context WIP allow setting service name from auto instrumentation context Dec 5, 2022
@pdelewski pdelewski force-pushed the hardcoded-service-name branch 3 times, most recently from 89bf331 to c81980d Compare December 5, 2022 17:27
@@ -78,11 +72,12 @@ private function convertSpan(SpanDataInterface $span): array
$startTimestamp = TimeUtil::nanosToMicros($span->getStartEpochNanos());
$endTimestamp = TimeUtil::nanosToMicros($span->getEndEpochNanos());

$serviceName = $span->getResource()->getAttributes()->get(ResourceAttributes::SERVICE_NAME) ?? 'zipkin';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must use default resource as fallback, spec:

Zipkin service name MUST be set to the value of the resource attribute: service.name. If no service.name is contained in a Span's Resource, it MUST be populated from the default Resource.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right, it's still work in progress

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nevay fixed fallback

@pdelewski pdelewski force-pushed the hardcoded-service-name branch 5 times, most recently from 1ce869f to 0b04c02 Compare December 6, 2022 11:50
@pdelewski pdelewski changed the title WIP allow setting service name from auto instrumentation context allow setting service name from auto instrumentation context Dec 6, 2022
@@ -23,25 +23,23 @@
*/
class Exporter implements SpanExporterInterface
{
public $name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed.

@pdelewski pdelewski force-pushed the hardcoded-service-name branch 2 times, most recently from 7dec032 to 448ac3a Compare December 6, 2022 20:09
@@ -40,12 +35,16 @@ private function convertSpan(SpanDataInterface $span): array
$startTimestamp = TimeUtil::nanosToMillis($span->getStartEpochNanos());
$endTimestamp = TimeUtil::nanosToMillis($span->getEndEpochNanos());

$serviceName = $span->getResource()->getAttributes()->get(ResourceAttributes::SERVICE_NAME)
??
ResourceInfoFactory::defaultResource()->getAttributes()->get(ResourceAttributes::SERVICE_NAME);
Copy link
Collaborator

@brettmc brettmc Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on how many detectors are enabled (by default, all of them are), this is a bit of overhead we could avoid? Perhaps setting a default/fallback service name in the constructor?
(also applies to a couple of other converters that also do this)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

@pdelewski pdelewski force-pushed the hardcoded-service-name branch 2 times, most recently from 824c9eb to c3b81ec Compare December 7, 2022 12:00
@@ -18,9 +20,9 @@ class SpanConverter implements SpanConverterInterface

private string $serviceName;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a better name might be fallbackServiceName or defaultServiceName ?

$row = $converter->convert([$span])[0];

$this->assertSame($span->getContext()->getSpanId(), $row['id']);
$this->assertSame($span->getContext()->getTraceId(), $row['traceId']);
$this->assertSame('1000000000000000', $row['parentId']);

$this->assertSame('test.name', $row['localEndpoint']['serviceName']);
$this->assertSame('unknown_service', $row['localEndpoint']['serviceName']);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might need to merge in main branch, this is something I changed in a commit in the last day or so... unknown_service:php

Copy link
Member Author

@pdelewski pdelewski Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's right.

@pdelewski pdelewski merged commit 7bfc121 into open-telemetry:main Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants