Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into laravel/hook/applic…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
ChrisLightfootWild committed Aug 13, 2023
2 parents da40eaf + 395b7b8 commit e376229
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Instrumentation/Laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"minimum-stability": "dev",
"require": {
"php": "^8.0",
"laravel/framework": "*",
"laravel/framework": ">=6.0",
"ext-opentelemetry": "*",
"open-telemetry/api": "^1.0.0beta10",
"open-telemetry/sem-conv": "^1"
Expand Down
14 changes: 13 additions & 1 deletion src/Instrumentation/Laravel/src/LaravelInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function register(): void
->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, $request->host())
->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::USER_AGENT_ORIGINAL, $request->userAgent())
Expand Down Expand Up @@ -152,4 +152,16 @@ private static function httpTarget(Request $request): string

return $query ? $request->path() . $question . $query : $request->path();
}

private static function httpHostName(Request $request): string
{
if (method_exists($request, 'host')) {
return $request->host();
}
if (method_exists($request, 'getHost')) {
return $request->getHost();
}

return '';
}
}

0 comments on commit e376229

Please sign in to comment.