Skip to content

Commit

Permalink
Laravel 6.x support (#185)
Browse files Browse the repository at this point in the history
* request illuminate check both getHost and host method
* add laravel version
* fix: Return blank string instead of null

Signed-off-by: Natsuki Ikeguchi <[email protected]>
Co-authored-by: Abhishek Surve <[email protected]>
  • Loading branch information
siketyan and abhisheksurve45 authored Aug 13, 2023
1 parent 70e5a29 commit c360626
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 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/LaravelInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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 @@ -116,4 +116,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 c360626

Please sign in to comment.