> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/setup-and-configuration/integrations/testing-frameworks-integration/improve-test-optimization-with-context-propagation.md).

# Improve Test Optimization With Context Propagation

SeaLights is using [Open Telemetry](https://opentelemetry.io/) to propagate the context of your tests, this allow to enrich the test optimization statistical model to an almost 1:1 relationship between a test and the code of the application it is testing.

There are 2 main ways to propagate the context of a test:

1. The utilization of a baggage
2. The utilization of a cookie

In order to set this up, these are the necessary steps you need to take:

1. Set up the testing framework to set either the baggage or the cookie with the test information, including:
   1. Test name
   2. Test session ID
2. Set up the front-end agent with the flag to enable Open Telemetry usage
3. Set up the backend agent with the flags to enable Open Telemetry usage

### Set Context Propagation on the Node Agent <a href="#heading-title-text" id="heading-title-text"></a>

In order to enable context propagation on the Node Agent, you will need to set the `--enableOpenTelemetry` flag when applying the `scan` command, for example:

{% code overflow="wrap" lineNumbers="true" %}

```
npx slnodejs scan --workspacepath ./MyApp --tokenfile sltoken.txt --buildsessionidfile buildSessionId --scm none --instrumentForBrowsers --enableOpenTelemetry --outputpath "sl_dist"
```

{% endcode %}

### Set Context Propagation on the Java Agent <a href="#heading-title-text" id="heading-title-text"></a>

In order to enable context propagation on the Java Agent, you will need to set the following flags when starting the test listener:

* sl.otelEnabled=true
* sl.otelConfiguration.enabled=true
* sl.otelConfiguration.loadEmbeddedAgent=true
* sl.featuresData.codeCoverageManagerVersion=v3

For example:

{% code overflow="wrap" lineNumbers="true" %}

```
-javaagent:/path/to/sl-test-listener.jar -Dsl.tags=backend -Dsl.labId=<lab ID> -Dsl.otelEnabled=true -Dsl.otelConfiguration.enabled=true -Dsl.otelConfiguration.loadEmbeddedAgent=true -Dsl.featuresData.codeCoverageManagerVersion=v3
```

{% endcode %}

## Testing Frameworks <a href="#heading-title-text" id="heading-title-text"></a>

### Setting Context Propagation with PlayWright <a href="#heading-title-text" id="heading-title-text"></a>

In order to set the context with the baggage, please follow [this guide](https://github.com/Sealights/sealights-integration-examples/tree/main/playwright-browser-agent-otel#2-setting-the-testsessionid-and-testname).

### Setting Context Propagation With Cypress <a href="#heading-title-text" id="heading-title-text"></a>

In order to set the context with the baggage, please follow [this guide](https://github.com/Sealights/sealights-integration-examples/blob/main/cypress-browser-agent-otel/README.md).

### Setting Context Propagation With Gauge <a href="#heading-title-text" id="heading-title-text"></a>

In order to set the context with the baggage, please follow [this guide](https://github.com/Sealights/sealights-integration-examples/blob/main/gauge-browser-agent-otel/README.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/integrations/testing-frameworks-integration/improve-test-optimization-with-context-propagation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
