|
4 | 4 |
|
5 | 5 | namespace OpenTelemetry\Context; |
6 | 6 |
|
| 7 | +/** |
| 8 | + * Immutable execution scoped propagation mechanism. |
| 9 | + * |
| 10 | + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#context |
| 11 | + */ |
7 | 12 | interface ContextInterface |
8 | 13 | { |
9 | 14 | /** |
10 | | - * @param non-empty-string $key |
| 15 | + * Creates a new context key. |
11 | 16 | * |
12 | | - * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/context/context.md#create-a-key |
| 17 | + * @param non-empty-string $key name of the key |
| 18 | + * @return ContextKeyInterface created key |
| 19 | + * |
| 20 | + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#create-a-key |
13 | 21 | */ |
14 | 22 | public static function createKey(string $key): ContextKeyInterface; |
15 | 23 |
|
| 24 | + /** |
| 25 | + * Returns the current context. |
| 26 | + * |
| 27 | + * @return ContextInterface current context |
| 28 | + * |
| 29 | + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#get-current-context |
| 30 | + */ |
16 | 31 | public static function getCurrent(): ContextInterface; |
17 | 32 |
|
18 | 33 | /** |
19 | | - * Makes `$this` the currently active {@see ContextInterface}. |
| 34 | + * Attaches this context as active context. |
| 35 | + * |
| 36 | + * The returned scope has to be {@link ScopeInterface::detach()}ed. In most |
| 37 | + * cases this should be done using a `try-finally` statement: |
| 38 | + * ```php |
| 39 | + * $scope = $context->activate(); |
| 40 | + * try { |
| 41 | + * // ... |
| 42 | + * } finally { |
| 43 | + * $scope->detach(); |
| 44 | + * } |
| 45 | + * ``` |
| 46 | + * |
| 47 | + * @return ScopeInterface scope to detach the context and restore the previous |
| 48 | + * context |
| 49 | + * |
| 50 | + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#attach-context |
20 | 51 | */ |
21 | 52 | public function activate(): ScopeInterface; |
22 | 53 |
|
23 | 54 | /** |
24 | | - * This adds a key/value pair to this Context. |
| 55 | + * Returns a context with the given key set to the given value. |
| 56 | + * |
| 57 | + * @template T |
| 58 | + * @param ContextKeyInterface<T> $key key to set |
| 59 | + * @param T|null $value value to set |
| 60 | + * @return ContextInterface a context with the given key set to `$value` |
25 | 61 | * |
26 | | - * @psalm-template T |
27 | | - * @psalm-param ContextKeyInterface<T> $key |
28 | | - * @psalm-param T|null $value |
| 62 | + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#set-value |
29 | 63 | */ |
30 | 64 | public function with(ContextKeyInterface $key, $value): ContextInterface; |
31 | 65 |
|
| 66 | + /** |
| 67 | + * Returns a context with the given value set. |
| 68 | + * |
| 69 | + * @param ImplicitContextKeyedInterface $value value to set |
| 70 | + * @return ContextInterface a context with the given `$value` |
| 71 | + * |
| 72 | + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#set-value |
| 73 | + */ |
32 | 74 | public function withContextValue(ImplicitContextKeyedInterface $value): ContextInterface; |
33 | 75 |
|
34 | 76 | /** |
35 | | - * Fetch a value from the Context given a key value. |
| 77 | + * Returns the value assigned to the given key. |
| 78 | + * |
| 79 | + * @template T |
| 80 | + * @param ContextKeyInterface<T> $key key to get |
| 81 | + * @return T|null value assigned to `$key`, or null if no such value exists |
36 | 82 | * |
37 | | - * @psalm-template T |
38 | | - * @psalm-param ContextKeyInterface<T> $key |
39 | | - * @psalm-return T|null |
| 83 | + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/README.md#get-value |
40 | 84 | */ |
41 | 85 | public function get(ContextKeyInterface $key); |
42 | 86 | } |
0 commit comments