> For the complete documentation index, see [llms.txt](https://archivedocs.stackstate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://archivedocs.stackstate.com/5.1/stackpacks/integrations/traefik.md).

# Traefik

The StackState Traefik integration provides the following functionality:

* Reporting Traefik frontends and backends as topology elements.
* Reporting all network connections between services, including network traffic telemetry.

Traefik is a [StackState curated integration](/5.1/stackpacks/integrations/about_integrations.md#stackstate-curated-integrations).

## Setup

### Installation

The StackState Traefik integration is included in the [Agent V2 StackPack](/5.1/stackpacks/integrations/agent.md). Currently, this integration supports tracing of Traefik requests using the Datadog tracing backend supported by Traefik.

### Configuration

Configure your Traefik instance to report [Datadog tracing data](https://doc.traefik.io/traefik/observability/tracing/datadog/) to StackState . Your Traefik.toml configuration file must include the following parameters:

```
# Tracing definition
[tracing]
  # Use the Datadog backend to send the Datadog Tracing format to StackState Agent
  backend = "datadog"

  # Component name used for your Traefik instance in StackState
  serviceName = "traefik"

  # Span name limit allows for name truncation in case of very long Frontend/Backend names
  # This can prevent certain tracing providers to drop traces that exceed their length limits
  spanNameLimit = 100

  [tracing.datadog]
    # StackState Agent Host Port instructs reporter to send spans to StackState  at this address
    localAgentHostPort = "agentHost:8126"

    # Applies a shared tag in a form of source:traefik to all the spans of the trace
    globalTag = "source:traefik"
```

### Integrate with Java traces

When using Traefik in conjunction with one of our language specific trace clients, for example, [StackState Java Trace Client - Java APM](/5.1/stackpacks/integrations/java-apm.md) it's important to note that you should use the `backend` name of your Traefik service as the `service-name` for the trace client to allow automatic merging of the service components within StackState.

For example, for the following `Traefik.toml`:

```
...
[frontends]
  [frontends.stackstate-demo-frontend]
  backend = "stackstate-demo-backend"
    [frontends.stackstate-demo-frontend.routes.test_1]
    rule = "Host:test.stackstate-demo-backend.localhost"
[backends]
  [[backends.stackstate-demo-backend]]
    # ...
    [[backends.stackstate-demo-backend].servers.server1]
    url = "..."
    ...
...
```

you should pass the following jvm argument when starting your java application: `-Dsts.service.name=stackstate-demo-backend`

or for a similar docker-compose configuration:

```
  stackstate-demo-app:
    image: stackstate-demo-app:latest
    pid: "host" # use pid:"host" to ensure pid's match with processes reported by the StackState process Agent
    ports:
      - '8081-8091:8081'
    depends_on:
      - another_app
      - stackstate-agent
    labels:
      - "traefik.frontend.rule=Host:stackstate-demo-app.docker.localhost"
      - "traefik.backend=stackstate-demo-app"
    environment:
      MAVEN_OPTS: |
      -Dsts.service.name=stackstate-demo-app
      -Dsts.agent.host=${DOCKER_HOST_IP}
      -Dsts.agent.port=8126
      -javaagent:/sts-java-agent.jar
```

## Troubleshooting

To verify whether the StackState Trace Agent has received traces, set the logging level to debug and check the `trace-agent.log`:

{% tabs %}
{% tab title="stackstate.yaml" %}

```
log_level: debug
```

{% endtab %}
{% endtabs %}

In Docker or Kubernetes, set the following environment variable for the StackState Agent

```
STS_LOG_LEVEL: "DEBUG"
```


---

# 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://archivedocs.stackstate.com/5.1/stackpacks/integrations/traefik.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.
