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

Update TraceAttributes to semconv to 1.22.0 #204

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Instrumentation/CodeIgniter/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ext-opentelemetry": "*",
"codeigniter4/framework": ">=4.0",
"open-telemetry/api": "^1.0.0beta10",
"open-telemetry/sem-conv": "^1"
"open-telemetry/sem-conv": "^1.22"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public static function register(): void

/** @psalm-suppress DeprecatedMethod */
$spanBuilder = $spanBuilder->setParent($parent)
->setAttribute(TraceAttributes::HTTP_URL, (string) $request->getUri())
->setAttribute(TraceAttributes::URL_FULL, (string) $request->getUri())
/** @phan-suppress-next-line PhanDeprecatedFunction */
->setAttribute(TraceAttributes::HTTP_METHOD, $request->getMethod(true))
->setAttribute(TraceAttributes::HTTP_REQUEST_CONTENT_LENGTH, $request->getHeaderLine('Content-Length'))
->setAttribute(TraceAttributes::HTTP_SCHEME, $request->getUri()->getScheme());
->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $request->getMethod(true))
->setAttribute(TraceAttributes::HTTP_REQUEST_BODY_SIZE, $request->getHeaderLine('Content-Length'))
->setAttribute(TraceAttributes::URL_SCHEME, $request->getUri()->getScheme());
}

$span = $spanBuilder->startSpan();
Expand All @@ -97,9 +97,9 @@ public static function register(): void
/** @psalm-suppress DeprecatedMethod */
/** @phan-suppress-next-line PhanDeprecatedFunction */
$statusCode = $response->getStatusCode();
$span->setAttribute(TraceAttributes::HTTP_STATUS_CODE, $statusCode);
$span->setAttribute(TraceAttributes::HTTP_FLAVOR, $response->getProtocolVersion());
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH, CodeIgniterInstrumentation::getResponseLength($response));
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $statusCode);
$span->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $response->getProtocolVersion());
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_BODY_SIZE, CodeIgniterInstrumentation::getResponseLength($response));

foreach ((array) (get_cfg_var('otel.instrumentation.http.response_headers') ?: []) as $header) {
if ($response->hasHeader($header)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function test_success()
$attributes = $this->storage[0]->getAttributes();
$this->assertCount(1, $this->storage);
$this->assertEquals('HTTP GET', $this->storage[0]->getName());
$this->assertEquals('http://example.com/index.php/home', $attributes->get(TraceAttributes::HTTP_URL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::HTTP_SCHEME));
$this->assertEquals('http://example.com/index.php/home', $attributes->get(TraceAttributes::URL_FULL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));
$this->assertEquals('Home.index', $attributes->get(TraceAttributes::HTTP_ROUTE));
$this->assertEquals(200, $attributes->get(TraceAttributes::HTTP_STATUS_CODE));
$this->assertEquals('1.1', $attributes->get(TraceAttributes::HTTP_FLAVOR));
$this->assertGreaterThan(0, $attributes->get(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH));
$this->assertEquals(200, $attributes->get(TraceAttributes::HTTP_RESPONSE_STATUS_CODE));
$this->assertEquals('1.1', $attributes->get(TraceAttributes::NETWORK_PROTOCOL_VERSION));
$this->assertGreaterThan(0, $attributes->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));
}

public function test_exception()
Expand All @@ -56,13 +56,13 @@ public function test_exception()
$attributes = $this->storage[0]->getAttributes();
$this->assertCount(1, $this->storage);
$this->assertEquals('HTTP GET', $this->storage[0]->getName());
$this->assertEquals('http://example.com/index.php/exception', $attributes->get(TraceAttributes::HTTP_URL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::HTTP_SCHEME));
$this->assertEquals('http://example.com/index.php/exception', $attributes->get(TraceAttributes::URL_FULL));
$this->assertEquals('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD));
$this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));
$this->assertEquals('Closure.index', $attributes->get(TraceAttributes::HTTP_ROUTE));
$this->assertNull($attributes->get(TraceAttributes::HTTP_STATUS_CODE));
$this->assertNull($attributes->get(TraceAttributes::HTTP_FLAVOR));
$this->assertNull($attributes->get(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH));
$this->assertNull($attributes->get(TraceAttributes::HTTP_RESPONSE_STATUS_CODE));
$this->assertNull($attributes->get(TraceAttributes::NETWORK_PROTOCOL_VERSION));
$this->assertNull($attributes->get(TraceAttributes::HTTP_RESPONSE_BODY_SIZE));

$status = $this->storage[0]->getStatus();
$this->assertEquals('Error', $status->getCode());
Expand Down
2 changes: 1 addition & 1 deletion src/Instrumentation/HttpAsyncClient/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"php": "^8.0",
"ext-opentelemetry": "*",
"open-telemetry/api": "^1.0.0beta10",
"open-telemetry/sem-conv": "^1",
"open-telemetry/sem-conv": "^1.22",
"php-http/httplug": "^2"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public static function register(): void
->spanBuilder(sprintf('HTTP %s', $request->getMethod()))
->setParent($parentContext)
->setSpanKind(SpanKind::KIND_CLIENT)
->setAttribute(TraceAttributes::HTTP_URL, (string) $request->getUri())
->setAttribute(TraceAttributes::HTTP_METHOD, $request->getMethod())
->setAttribute(TraceAttributes::HTTP_FLAVOR, $request->getProtocolVersion())
->setAttribute(TraceAttributes::URL_FULL, (string) $request->getUri())
->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $request->getMethod())
->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $request->getProtocolVersion())
->setAttribute(TraceAttributes::USER_AGENT_ORIGINAL, $request->getHeaderLine('User-Agent'))
->setAttribute(TraceAttributes::HTTP_REQUEST_CONTENT_LENGTH, $request->getHeaderLine('Content-Length'))
->setAttribute(TraceAttributes::NET_PEER_NAME, $request->getUri()->getHost())
->setAttribute(TraceAttributes::NET_PEER_PORT, $request->getUri()->getPort())
->setAttribute(TraceAttributes::HTTP_REQUEST_BODY_SIZE, $request->getHeaderLine('Content-Length'))
->setAttribute(TraceAttributes::SERVER_ADDRESS, $request->getUri()->getHost())
->setAttribute(TraceAttributes::SERVER_PORT, $request->getUri()->getPort())
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
->setAttribute(TraceAttributes::CODE_FILEPATH, $filename)
Expand Down Expand Up @@ -96,9 +96,9 @@ public static function register(): void

$promise->then(
onFulfilled: function (ResponseInterface $response) use ($span) {
$span->setAttribute(TraceAttributes::HTTP_STATUS_CODE, $response->getStatusCode());
$span->setAttribute(TraceAttributes::HTTP_FLAVOR, $response->getProtocolVersion());
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH, $response->getHeaderLine('Content-Length'));
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $response->getStatusCode());
$span->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $response->getProtocolVersion());
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_BODY_SIZE, $response->getHeaderLine('Content-Length'));
if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) {
$span->setStatus(StatusCode::STATUS_ERROR);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Instrumentation/IO/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"php": "^8.2",
"ext-opentelemetry": "*",
"open-telemetry/api": "^1.0.0beta10",
"open-telemetry/sem-conv": "^1"
"open-telemetry/sem-conv": "^1.22"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
Expand Down
2 changes: 1 addition & 1 deletion src/Instrumentation/Laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ext-opentelemetry": "*",
"laravel/framework": ">=6.0",
"open-telemetry/api": "^1.0.0beta10",
"open-telemetry/sem-conv": "^1"
"open-telemetry/sem-conv": "^1.22"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
Expand Down
26 changes: 13 additions & 13 deletions src/Instrumentation/Laravel/src/HttpInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public static function register(CachedInstrumentation $instrumentation): void
$parent = Globals::propagator()->extract($request, HeadersPropagator::instance());
$span = $builder
->setParent($parent)
->setAttribute(TraceAttributes::HTTP_URL, $request->fullUrl())
->setAttribute(TraceAttributes::HTTP_METHOD, $request->method())
->setAttribute(TraceAttributes::HTTP_REQUEST_CONTENT_LENGTH, $request->header('Content-Length'))
->setAttribute(TraceAttributes::HTTP_SCHEME, $request->getScheme())
->setAttribute(TraceAttributes::HTTP_FLAVOR, $request->getProtocolVersion())
->setAttribute(TraceAttributes::HTTP_CLIENT_IP, $request->ip())
->setAttribute(TraceAttributes::HTTP_TARGET, self::httpTarget($request))
->setAttribute(TraceAttributes::NET_HOST_NAME, self::httpHostName($request))
->setAttribute(TraceAttributes::NET_HOST_PORT, $request->getPort())
->setAttribute(TraceAttributes::NET_PEER_PORT, $request->server('REMOTE_PORT'))
->setAttribute(TraceAttributes::URL_FULL, $request->fullUrl())
->setAttribute(TraceAttributes::HTTP_REQUEST_METHOD, $request->method())
->setAttribute(TraceAttributes::HTTP_REQUEST_BODY_SIZE, $request->header('Content-Length'))
->setAttribute(TraceAttributes::URL_SCHEME, $request->getScheme())
->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $request->getProtocolVersion())
->setAttribute(TraceAttributes::NETWORK_PEER_ADDRESS, $request->ip())
->setAttribute(TraceAttributes::URL_PATH, self::httpTarget($request))
->setAttribute(TraceAttributes::SERVER_ADDRESS, self::httpHostName($request))
->setAttribute(TraceAttributes::SERVER_PORT, $request->getPort())
->setAttribute(TraceAttributes::CLIENT_PORT, $request->server('REMOTE_PORT'))
->setAttribute(TraceAttributes::USER_AGENT_ORIGINAL, $request->userAgent())
->startSpan();
$request->attributes->set(SpanInterface::class, $span);
Expand All @@ -75,9 +75,9 @@ public static function register(CachedInstrumentation $instrumentation): void
if ($response->getStatusCode() >= 400) {
$span->setStatus(StatusCode::STATUS_ERROR);
}
$span->setAttribute(TraceAttributes::HTTP_STATUS_CODE, $response->getStatusCode());
$span->setAttribute(TraceAttributes::HTTP_FLAVOR, $response->getProtocolVersion());
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH, $response->headers->get('Content-Length'));
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $response->getStatusCode());
$span->setAttribute(TraceAttributes::NETWORK_PROTOCOL_VERSION, $response->getProtocolVersion());
$span->setAttribute(TraceAttributes::HTTP_RESPONSE_BODY_SIZE, $response->headers->get('Content-Length'));
}

$span->end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function recordRequest(RequestSending $request): void
$span = $this->instrumentation->tracer()->spanBuilder('HTTP ' . $request->request->method())
->setSpanKind(SpanKind::KIND_CLIENT)
->setAttributes([
TraceAttributes::HTTP_METHOD => $request->request->method(),
TraceAttributes::HTTP_URL => $processedUrl,
TraceAttributes::HTTP_TARGET => $parsedUrl['path'] ?? '',
TraceAttributes::HTTP_REQUEST_METHOD => $request->request->method(),
TraceAttributes::URL_FULL => $processedUrl,
TraceAttributes::URL_PATH => $parsedUrl['path'] ?? '',
TraceAttributes::HTTP_HOST => $parsedUrl['host'] ?? '',
TraceAttributes::HTTP_SCHEME => $parsedUrl['scheme'] ?? '',
TraceAttributes::NET_PEER_NAME => $parsedUrl['host'] ?? '',
TraceAttributes::NET_PEER_PORT => $parsedUrl['port'] ?? '',
TraceAttributes::URL_SCHEME => $parsedUrl['scheme'] ?? '',
TraceAttributes::SERVER_ADDRESS => $parsedUrl['host'] ?? '',
TraceAttributes::SERVER_PORT => $parsedUrl['port'] ?? '',
])
->startSpan();
$this->spans[$this->createRequestComparisonHash($request->request)] = $span;
Expand Down Expand Up @@ -84,8 +84,8 @@ public function recordResponse(ResponseReceived $request): void
}

$span->setAttributes([
TraceAttributes::HTTP_STATUS_CODE => $request->response->status(),
TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH => $request->response->header('Content-Length'),
TraceAttributes::HTTP_RESPONSE_STATUS_CODE => $request->response->status(),
TraceAttributes::HTTP_RESPONSE_BODY_SIZE => $request->response->header('Content-Length'),
]);

$this->maybeRecordError($span, $request->response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function test_cache_log_db(): void
$this->assertCount(2, $this->storage);
$span = $this->storage->offsetGet(1);
$this->assertSame('HTTP GET', $span->getName());
$this->assertSame('http://localhost/hello', $span->getAttributes()->get(TraceAttributes::HTTP_URL));
$this->assertSame('http://localhost/hello', $span->getAttributes()->get(TraceAttributes::URL_FULL));
$this->assertCount(5, $span->getEvents());
$this->assertSame('cache set', $span->getEvents()[0]->getName());
$this->assertSame('Log info', $span->getEvents()[1]->getName());
Expand Down
2 changes: 1 addition & 1 deletion src/Instrumentation/MongoDB/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ext-json": "*",
"mongodb/mongodb": "^1.15",
"open-telemetry/api": "^1.0.0beta12",
"open-telemetry/sem-conv": "^1"
"open-telemetry/sem-conv": "^1.22"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function commandStarted(CommandStartedEvent $event): void
->setAttribute(TraceAttributes::DB_NAME, $databaseName)
->setAttribute(TraceAttributes::DB_CONNECTION_STRING, $connectionString)
->setAttribute(TraceAttributes::DB_OPERATION, $commandName)
->setAttribute(TraceAttributes::NET_PEER_NAME, $isSocket ? null : $host)
->setAttribute(TraceAttributes::NET_PEER_PORT, $isSocket ? null : $port)
->setAttribute(TraceAttributes::NET_TRANSPORT, $isSocket ? 'unix' : 'tcp')
->setAttribute(TraceAttributes::SERVER_ADDRESS, $isSocket ? null : $host)
->setAttribute(TraceAttributes::SERVER_PORT, $isSocket ? null : $port)
->setAttribute(TraceAttributes::NETWORK_TRANSPORT, $isSocket ? 'unix' : 'tcp')
->setAttribute(TraceAttributes::DB_STATEMENT, ($this->commandSerializer)($command))
->setAttribute(TraceAttributes::DB_MONGODB_COLLECTION, $collectionName)
->setAttribute(MongoDBTraceAttributes::DB_MONGODB_MASTER, $info['ismaster'] ?? null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function test_mongodb_find_one(): void
self::assertSame('mongodb://127.0.0.1:27017/db', $attributes->get(TraceAttributes::DB_CONNECTION_STRING));
self::assertSame('find', $attributes->get(TraceAttributes::DB_OPERATION));
self::assertSame(self::COLLECTION_NAME, $attributes->get(TraceAttributes::DB_MONGODB_COLLECTION));
self::assertSame('127.0.0.1', $attributes->get(TraceAttributes::NET_PEER_NAME));
self::assertSame(27017, $attributes->get(TraceAttributes::NET_PEER_PORT));
self::assertSame('tcp', $attributes->get(TraceAttributes::NET_TRANSPORT));
self::assertSame('127.0.0.1', $attributes->get(TraceAttributes::SERVER_ADDRESS));
self::assertSame(27017, $attributes->get(TraceAttributes::SERVER_PORT));
self::assertSame('tcp', $attributes->get(TraceAttributes::NETWORK_TRANSPORT));
self::assertTrue($attributes->get(MongoDBTraceAttributes::DB_MONGODB_MASTER));
self::assertFalse($attributes->get(MongoDBTraceAttributes::DB_MONGODB_READ_ONLY));
self::assertIsNumeric($attributes->get(MongoDBTraceAttributes::DB_MONGODB_CONNECTION_ID));
Expand Down
2 changes: 1 addition & 1 deletion src/Instrumentation/PDO/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ext-pdo": "*",
"ext-opentelemetry": "*",
"open-telemetry/api": "^1.0.0beta10",
"open-telemetry/sem-conv": "^1"
"open-telemetry/sem-conv": "^1.22"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
Expand Down
2 changes: 1 addition & 1 deletion src/Instrumentation/Psr15/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"php": "^8.0",
"ext-opentelemetry": "*",
"open-telemetry/api": "^1.0.0beta10",
"open-telemetry/sem-conv": "^1",
"open-telemetry/sem-conv": "^1.22",
"psr/http-server-middleware": "^1"
},
"autoload": {
Expand Down
Loading
Loading