Skip to content

Commit

Permalink
Amend Symfony tests to include server-timing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricziel committed Nov 23, 2023
1 parent d0888a4 commit 7daf35a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration;

use OpenTelemetry\Contrib\Propagation\ServerTiming\ServerTimingPropagator;
use OpenTelemetry\Contrib\Propagation\TraceResponse\TraceResponsePropagator;
use OpenTelemetry\SemConv\TraceAttributes;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand Down Expand Up @@ -62,6 +63,12 @@ public function test_http_kernel_handle_attributes(): void
$response->headers->all(),
'traceresponse header is present if TraceResponsePropagator is present'
);

$this->assertArrayHasKey(
ServerTimingPropagator::SERVER_TIMING,
$response->headers->all(),
'server-timings header is present if ServerTimingPropagator is present'
);
}

public function test_http_kernel_handle_stream_response(): void
Expand All @@ -81,6 +88,12 @@ public function test_http_kernel_handle_stream_response(): void
$response->headers->all(),
'traceresponse header is present if TraceResponsePropagator is present'
);

$this->assertArrayHasKey(
ServerTimingPropagator::SERVER_TIMING,
$response->headers->all(),
'server-timings header is present if ServerTimingPropagator is present'
);
}

public function test_http_kernel_handle_binary_file_response(): void
Expand All @@ -97,6 +110,12 @@ public function test_http_kernel_handle_binary_file_response(): void
$response->headers->all(),
'traceresponse header is present if TraceResponsePropagator is present'
);

$this->assertArrayHasKey(
ServerTimingPropagator::SERVER_TIMING,
$response->headers->all(),
'server-timings header is present if ServerTimingPropagator is present'
);
}

public function test_http_kernel_handle_with_empty_route(): void
Expand All @@ -115,6 +134,12 @@ public function test_http_kernel_handle_with_empty_route(): void
$response->headers->all(),
'traceresponse header is present if TraceResponsePropagator is present'
);

$this->assertArrayHasKey(
ServerTimingPropagator::SERVER_TIMING,
$response->headers->all(),
'server-timings header is present if ServerTimingPropagator is present'
);
}

public function test_http_kernel_handle_without_route(): void
Expand All @@ -131,6 +156,12 @@ public function test_http_kernel_handle_without_route(): void
$response->headers->all(),
'traceresponse header is present if TraceResponsePropagator is present'
);

$this->assertArrayHasKey(
ServerTimingPropagator::SERVER_TIMING,
$response->headers->all(),
'server-timings header is present if ServerTimingPropagator is present'
);
}

private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, RequestStack $requestStack = null, array $arguments = []): HttpKernel
Expand Down
23 changes: 12 additions & 11 deletions src/Propagation/ServerTiming/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-propagator-traceresponse/releases)
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-propagator-server-timing/releases)
[![Issues](https://img.shields.io/badge/issues-pink)](https://github.com/open-telemetry/opentelemetry-php/issues)
[![Source](https://img.shields.io/badge/source-contrib-green)](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Propagation/TraceResponse)
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-propagator-traceresponse)
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-propagation-traceresponse/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-propagation-traceresponse/)
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-propagation-traceresponse/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-propagation-traceresponse/)
[![Source](https://img.shields.io/badge/source-contrib-green)](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Propagation/ServerTiming)
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-propagator-server-timing)
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-propagation-traceresponse/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-propagation-server-timing/)
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-propagation-traceresponse/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-propagation-server-timing/)

This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.

# OpenTelemetry TraceResponse Propagator
# OpenTelemetry ServerTiming Propagator

**Note:** This package is experimental as `traceresponse` is currently an editors' draft.

This package provides a [Trace Context HTTP Response Headers Format](https://w3c.github.io/trace-context/#trace-context-http-response-headers-format)
This package provides a [Server-Timing](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing)
propagator to inject the current span context into Response datastructures.

The main goal is to allow client-side technology (Real User Monitoring, HTTP Clients) to record
the server side context in order to allow referencing it.

Server-Timing response headers are especially useful for this approach, as they are accessible on the client side,
even for the initial page load.

## Requirements

* OpenTelemetry SDK and exporters (required to actually export traces)
Expand Down Expand Up @@ -45,14 +46,14 @@ $propagationSetter = new class implements OpenTelemetry\Context\Propagation\Prop
$carrier->headers->set($key, $value);
}
};
$propagator = new TraceResponseProgator();
$propagator = new ServerTimingPropagator();
$propagator->inject($response, $propagationSetter, $scope->context());
```

## Installation via composer

```bash
$ composer require open-telemetry/opentelemetry-propagation-traceresponse
$ composer require open-telemetry/opentelemetry-propagation-server-timing
```

## Installing dependencies and executing tests
Expand Down

0 comments on commit 7daf35a

Please sign in to comment.