Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GELF Log

This Traefik plugin is as middleware to send request headers along with optional TraceId and Request Start Time to a GELF compatible ingest tool.

docker-compose.yml:

version: "3.3"

services:
  traefik:
    image: traefik:v2.4
    command:
      - --api.insecure=true
      - --entrypoints.web.address=:80
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --experimental.plugins.gelflog.modulename=github.com/itninja04/traefik-gelf-plugin
      - --experimental.plugins.gelflog.version=v0.1.91
    ports:
      - 80:80
      - 8080:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - test
  whoami:
    image: containous/whoami
    labels:
      traefik.enable: true
      traefik.http.routers.whoami.rule: Host(`localhost`)
      traefik.http.routers.whoami.entrypoints: web
      traefik.http.middlewares.gelf-logger.plugin.gelflog.debug: true
      traefik.http.middlewares.gelf-logger.plugin.gelflog.gelfEndpoint: "127.0.0.1"
      traefik.http.middlewares.gelf-logger.plugin.gelflog.gelfPort: 12202
      # set the Hostname Override if you want to change the hostname sent to your GELF endpoint
      traefik.http.middlewares.gelf-logger.plugin.gelflog.hostnameOverride: ""
      # default is true, set to false to stop sending a TraceId
      traefik.http.middlewares.gelf-logger.plugin.gelflog.emitTraceId: true
      # default is X-TraceId change this to whatever header name you want
      traefik.http.middlewares.gelf-logger.plugin.gelflog.traceIdHeader: "X-TraceId"
      # default is true, set to false to stop sending a Request Start timestamp
      traefik.http.middlewares.gelf-logger.plugin.gelflog.emitRequestStart: true
      # default is X-Request-Start change this to whatever header name you want
      traefik.http.middlewares.gelf-logger.plugin.gelflog.requestStartTimeHeader: "X-Request-Start"
      traefik.http.routers.whoami.middlewares: gelf-logger
    networks:
      - test

networks:
  test:

Configuration

To configure this plugin you should add its configuration to the Traefik dynamic configuration as explained here. The following snippet shows how to configure this plugin with the File provider in TOML and YAML:

[http.middlewares]
  [http.middlewares.gelf-logger.traefik-gelf-plugin]
    debug = true
    gelfEndpoint = "127.0.0.1"
    gelfPort = 12202
    hostnameOverride = ""
    emitTraceId = true
    traceIdHeader = "X-TraceId"
    emitRequestStart = true
    requestStartTimeHeader = "X-Request-Start"
http:
  middlewares:
    gelf-logger:
      plugin:
        traefik-gelf-plugin:
          debug: true
          gelfEndpoint: "127.0.0.1"
          gelfPort: 12202
          hostnameOverride: ""
          emitTraceId: true
          traceIdHeader: "X-TraceId"
          emitRequestStart: true
          requestStartTimeHeader: "X-Request-Start"

Applying Middleware

You can apply the middleware on a case by case basis using the docker-compose.yml example above. However if you want to apply it to every request you can apply it to an entrypoint as follows:

YAML

entypoints:
  websecure:
    address: :443
    http:
      middlewares:
        - gelf-logger@file

TOML

#TOML
[entryPoints.websecure]
  address = ":443"
  [entryPoints.websecure.http]
    middlewares = ["gelf-logger@file"]

CLI

--entrypoints.websecure.address=:443
--entrypoints.websecure.http.middlewares=gelf-logger@file

About

This Traefik plugin is as middleware to send request headers along with optional TraceId and Request Start Time to a GELF compatible ingest tool.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages