Skip to content

Commit f2c03c7

Browse files
committed
Addressed review comments
1 parent 418dfb1 commit f2c03c7

File tree

6 files changed

+48
-77
lines changed

6 files changed

+48
-77
lines changed

.gitsplit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ splits:
6161
- prefix: "src/Instrumentation/ReactPHP"
6262
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-reactphp.git"
6363
- prefix: "src/Instrumentation/Session"
64-
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-php-session.git"
64+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-session.git"
6565
- prefix: "src/Instrumentation/Slim"
6666
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-slim.git"
6767
- prefix: "src/Instrumentation/Symfony"

src/Instrumentation/Session/README.md

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This package provides auto-instrumentation for PHP's native session functions.
55
## Installation
66

77
```bash
8-
composer require open-telemetry/opentelemetry-auto-php-session
8+
composer require open-telemetry/opentelemetry-auto-session
99
```
1010

1111
## Usage
@@ -33,57 +33,43 @@ session_destroy();
3333
When `session_start()` is called, a span named `session.start` is created with the following attributes:
3434

3535
- `code.function_name`: The function name (`session_start`)
36-
- `code.file_path`: The file path where the function was called
37-
- `code.line_number`: The line number where the function was called
38-
- `session.options.*`: Any options passed to `session_start()`
39-
- `session.id`: The session ID (if session was successfully started)
40-
- `session.name`: The session name (if session was successfully started)
41-
- `session.status`: Either "active" or "inactive"
42-
- `session.cookie.*`: Session cookie parameters
36+
- `php.session.options.*`: Any options passed to `session_start()`
37+
- `php.session.id`: The session ID (if session was successfully started)
38+
- `php.session.name`: The session name (if session was successfully started)
39+
- `php.session.status`: Either "active" or "inactive"
40+
- `php.session.cookie.*`: Session cookie parameters
4341

4442
### session.destroy
4543

4644
When `session_destroy()` is called, a span named `session.destroy` is created with the following attributes:
4745

4846
- `code.function_name`: The function name (`session_destroy`)
49-
- `code.file_path`: The file path where the function was called
50-
- `code.line_number`: The line number where the function was called
51-
- `session.id`: The session ID (if available)
52-
- `session.name`: The session name (if available)
53-
- `session.destroy.success`: Boolean indicating if the session was successfully destroyed
47+
- `php.session.id`: The session ID (if available)
48+
- `php.session.name`: The session name (if available)
5449

5550
### session.write_close
5651

5752
When `session_write_close()` is called, a span named `session.write_close` is created with the following attributes:
5853

5954
- `code.function.name`: The function name (`session_write_close`)
60-
- `code.filepath`: The file path where the function was called
61-
- `code.lineno`: The line number where the function was called
62-
- `session.id`: The session ID (if available)
63-
- `session.name`: The session name (if available)
64-
- `session.write_close.success`: Boolean indicating if the session was successfully written and closed
55+
- `php.session.id`: The session ID (if available)
56+
- `php.session.name`: The session name (if available)
6557

6658
### session.unset
6759

6860
When `session_unset()` is called, a span named `session.unset` is created with the following attributes:
6961

7062
- `code.function.name`: The function name (`session_unset`)
71-
- `code.filepath`: The file path where the function was called
72-
- `code.lineno`: The line number where the function was called
73-
- `session.id`: The session ID (if available)
74-
- `session.name`: The session name (if available)
75-
- `session.unset.success`: Boolean indicating if the session variables were successfully unset
63+
- `php.session.id`: The session ID (if available)
64+
- `php.session.name`: The session name (if available)
7665

7766
### session.abort
7867

7968
When `session_abort()` is called, a span named `session.abort` is created with the following attributes:
8069

8170
- `code.function.name`: The function name (`session_abort`)
82-
- `code.filepath`: The file path where the function was called
83-
- `code.lineno`: The line number where the function was called
84-
- `session.id`: The session ID (if available)
85-
- `session.name`: The session name (if available)
86-
- `session.abort.success`: Boolean indicating if the session was successfully aborted
71+
- `php.session.id`: The session ID (if available)
72+
- `php.session.name`: The session name (if available)
8773

8874
## License
8975

src/Instrumentation/Session/_register.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111

1212
if (extension_loaded('opentelemetry') === false) {
13-
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry IO auto-instrumentation', E_USER_WARNING);
13+
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry Session auto-instrumentation', E_USER_WARNING);
1414

1515
return;
1616
}

src/Instrumentation/Session/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "open-telemetry/opentelemetry-auto-php-session",
2+
"name": "open-telemetry/opentelemetry-auto-session",
33
"description": "OpenTelemetry auto-instrumentation for PHP Session functions",
44
"keywords": ["opentelemetry", "otel", "open-telemetry", "tracing", "php", "session"],
55
"type": "library",

src/Instrumentation/Session/src/PhpSessionInstrumentation.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function register(): void
2525
$instrumentation = new CachedInstrumentation(
2626
'io.opentelemetry.contrib.php.session',
2727
null,
28-
Version::VERSION_1_32_0->url(),
28+
Version::VERSION_1_36_0->url(),
2929
);
3030

3131
self::_hook($instrumentation, null, 'session_start', 'session.start');
@@ -44,9 +44,10 @@ private static function _hook(CachedInstrumentation $instrumentation, ?string $c
4444
hook(
4545
class: $class,
4646
function: $function,
47+
/** @psalm-suppress UnusedClosureParam */
4748
pre: static function ($object, ?array $params, ?string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation, $name) {
4849
/** @psalm-suppress ArgumentTypeCoercion */
49-
$builder = self::makeBuilder($instrumentation, $name, $function, $filename, $lineno);
50+
$builder = self::makeBuilder($instrumentation, $name, $function);
5051
self::addParams($builder, $function, $params);
5152
$parent = Context::getCurrent();
5253
$span = $builder->startSpan();
@@ -61,17 +62,13 @@ function: $function,
6162
private static function makeBuilder(
6263
CachedInstrumentation $instrumentation,
6364
string $name,
64-
string $function,
65-
?string $filename,
66-
?int $lineno
65+
string $function
6766
): SpanBuilderInterface {
6867
/** @psalm-suppress ArgumentTypeCoercion */
6968
return $instrumentation->tracer()
7069
->spanBuilder($name)
7170
->setSpanKind(SpanKind::KIND_INTERNAL)
72-
->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, $function)
73-
->setAttribute(TraceAttributes::CODE_FILE_PATH, $filename)
74-
->setAttribute(TraceAttributes::CODE_LINE_NUMBER, $lineno);
71+
->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, $function);
7572
}
7673

7774
private static function end(?Throwable $exception, string $function): void
@@ -86,52 +83,47 @@ private static function end(?Throwable $exception, string $function): void
8683
// Add session-specific attributes in the post hook
8784
if ($function === 'session_start') {
8885
$isSessionActive = !empty(session_id());
89-
$span->setAttribute('session.id', session_id());
90-
$span->setAttribute('session.name', session_name());
91-
$span->setAttribute('session.status', $isSessionActive ? 'active' : 'inactive');
86+
$span->setAttribute('php.session.id', session_id());
87+
$span->setAttribute('php.session.name', session_name());
88+
$span->setAttribute('php.session.status', $isSessionActive ? 'active' : 'inactive');
9289

9390
// Add session cookie parameters
9491
$cookieParams = session_get_cookie_params();
9592
foreach ($cookieParams as $key => $value) {
9693
if (is_scalar($value)) {
97-
$span->setAttribute("session.cookie.$key", $value);
94+
$span->setAttribute("php.session.cookie.$key", $value);
9895
}
9996
}
100-
} elseif ($function === 'session_destroy') {
101-
$span->setAttribute('session.destroy.success', $exception === null);
10297
} elseif ($function === 'session_write_close') {
10398
$sessionId = session_id();
10499
$sessionName = session_name();
105100

106101
// Add session information
107102
if (!empty($sessionId)) {
108-
$span->setAttribute('session.id', $sessionId);
109-
$span->setAttribute('session.name', $sessionName);
103+
$span->setAttribute('php.session.id', $sessionId);
104+
$span->setAttribute('php.session.name', $sessionName);
110105
}
111106

112-
$span->setAttribute('session.write_close.success', $exception === null);
113107
} elseif ($function === 'session_unset') {
114108
$sessionId = session_id();
115109
$sessionName = session_name();
116110

117111
// Add session information
118112
if (!empty($sessionId)) {
119-
$span->setAttribute('session.id', $sessionId);
120-
$span->setAttribute('session.name', $sessionName);
113+
$span->setAttribute('php.session.id', $sessionId);
114+
$span->setAttribute('php.session.name', $sessionName);
121115
}
122116

123-
$span->setAttribute('session.unset.success', $exception === null);
124117
} elseif ($function === 'session_abort') {
125118
$sessionId = session_id();
126119
$sessionName = session_name();
127120

128121
// Add session information
129122
if (!empty($sessionId)) {
130-
$span->setAttribute('session.id', $sessionId);
131-
$span->setAttribute('session.name', $sessionName);
123+
$span->setAttribute('php.session.id', $sessionId);
124+
$span->setAttribute('php.session.name', $sessionName);
132125
}
133126

134-
$span->setAttribute('session.abort.success', $exception === null);
135127
}
136128
if ($exception) {
137129
$span->recordException($exception);
@@ -154,7 +146,7 @@ private static function addParams(SpanBuilderInterface $builder, string $functio
154146
if (isset($params[0]) && is_array($params[0])) {
155147
foreach ($params[0] as $key => $value) {
156148
if (is_scalar($value)) {
157-
$builder->setAttribute("session.options.$key", $value);
149+
$builder->setAttribute("php.session.options.$key", $value);
158150
}
159151
}
160152
}

src/Instrumentation/Session/tests/Integration/PhpSessionInstrumentationTest.php

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ public function test_session_start(): void
5959
$this->assertEquals('session_start', $attributes->get(TraceAttributes::CODE_FUNCTION_NAME));
6060

6161
// Check session options were recorded
62-
$this->assertTrue($attributes->get('session.options.read_and_close'));
63-
$this->assertEquals(3600, $attributes->get('session.options.cookie_lifetime'));
62+
$this->assertTrue($attributes->get('php.session.options.read_and_close'));
63+
$this->assertEquals(3600, $attributes->get('php.session.options.cookie_lifetime'));
6464

6565
// Check session information
66-
$this->assertEquals(session_id(), $attributes->get('session.id'));
67-
$this->assertEquals(session_name(), $attributes->get('session.name'));
68-
$this->assertEquals('active', $attributes->get('session.status'));
66+
$this->assertEquals(session_id(), $attributes->get('php.session.id'));
67+
$this->assertEquals(session_name(), $attributes->get('php.session.name'));
68+
$this->assertEquals('active', $attributes->get('php.session.status'));
6969

7070
// Check cookie parameters
7171
$cookieParams = session_get_cookie_params();
7272
foreach ($cookieParams as $key => $value) {
7373
if (is_scalar($value)) {
74-
$this->assertEquals($value, $attributes->get("session.cookie.$key"));
74+
$this->assertEquals($value, $attributes->get("php.session.cookie.$key"));
7575
}
7676
}
7777

@@ -109,7 +109,6 @@ public function test_session_destroy(): void
109109

110110
// Check status
111111
$this->assertEquals(StatusCode::STATUS_OK, $span->getStatus()->getCode());
112-
$this->assertTrue($attributes->get('session.destroy.success'));
113112
}
114113
/**
115114
* @runInSeparateProcess
@@ -121,16 +120,13 @@ public function test_session_write_close(): void
121120

122121
// Set a session variable
123122
$_SESSION['test'] = 'value';
124-
125-
// Clear the storage to only capture the write_close operation
126-
$this->storage->exchangeArray([]);
127-
123+
128124
// Write and close the session
129125
session_write_close();
130126

131127
// Verify the span was created
132-
$this->assertCount(1, $this->storage);
133-
$span = $this->storage[0];
128+
$this->assertCount(2, $this->storage);
129+
$span = $this->storage[1];
134130

135131
// Check span name
136132
$this->assertEquals('session.write_close', $span->getName());
@@ -140,12 +136,11 @@ public function test_session_write_close(): void
140136
$this->assertEquals('session_write_close', $attributes->get(TraceAttributes::CODE_FUNCTION_NAME));
141137

142138
// Check session information
143-
$this->assertNotNull($attributes->get('session.id'));
144-
$this->assertNotNull($attributes->get('session.name'));
139+
$this->assertEquals(session_id(), $attributes->get('php.session.id'));
140+
$this->assertNotNull($attributes->get('php.session.name'));
145141

146142
// Check status
147143
$this->assertEquals(StatusCode::STATUS_OK, $span->getStatus()->getCode());
148-
$this->assertTrue($attributes->get('session.write_close.success'));
149144
}
150145

151146
/**
@@ -177,12 +172,11 @@ public function test_session_unset(): void
177172
$this->assertEquals('session_unset', $attributes->get(TraceAttributes::CODE_FUNCTION_NAME));
178173

179174
// Check session information
180-
$this->assertNotNull($attributes->get('session.id'));
181-
$this->assertNotNull($attributes->get('session.name'));
175+
$this->assertNotNull($attributes->get('php.session.id'));
176+
$this->assertNotNull($attributes->get('php.session.name'));
182177

183178
// Check status
184179
$this->assertEquals(StatusCode::STATUS_OK, $span->getStatus()->getCode());
185-
$this->assertTrue($attributes->get('session.unset.success'));
186180

187181
// Clean up
188182
session_destroy();
@@ -217,12 +211,11 @@ public function test_session_abort(): void
217211
$this->assertEquals('session_abort', $attributes->get(TraceAttributes::CODE_FUNCTION_NAME));
218212

219213
// Check session information
220-
$this->assertNotNull($attributes->get('session.id'));
221-
$this->assertNotNull($attributes->get('session.name'));
214+
$this->assertNotNull($attributes->get('php.session.id'));
215+
$this->assertNotNull($attributes->get('php.session.name'));
222216

223217
// Check status
224218
$this->assertEquals(StatusCode::STATUS_OK, $span->getStatus()->getCode());
225-
$this->assertTrue($attributes->get('session.abort.success'));
226219
}
227220

228221
/**

0 commit comments

Comments
 (0)