-
Notifications
You must be signed in to change notification settings - Fork 193
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
allow setting service name from auto instrumentation context #881
Conversation
66a0772
to
2a789e0
Compare
Codecov Report
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
IMO the service name should not be a constructor argument and should be read in |
Thx. That's the discussion I wanted to start opening this PR |
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 |
@Nevay I'm currently looking into this code and have some concerns.
its execution leads to execution of Should not we read and update |
Yes,
'serviceName' => $span->getResource()->getAttributes()->get(ResourceAttributes::SERVICE_NAME), |
Thx. That's exactly what I was thinking about |
89bf331
to
c81980d
Compare
src/Contrib/Zipkin/SpanConverter.php
Outdated
@@ -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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nevay fixed fallback
1ce869f
to
0b04c02
Compare
src/Contrib/Newrelic/Exporter.php
Outdated
@@ -23,25 +23,23 @@ | |||
*/ | |||
class Exporter implements SpanExporterInterface | |||
{ | |||
public $name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed.
7dec032
to
448ac3a
Compare
@@ -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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
824c9eb
to
c3b81ec
Compare
@@ -18,9 +20,9 @@ class SpanConverter implements SpanConverterInterface | |||
|
|||
private string $serviceName; |
There was a problem hiding this comment.
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']); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's right.
c3b81ec
to
54845a0
Compare
54845a0
to
31d358a
Compare
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.