Skip to content

Commit

Permalink
Allow to set the opentracing forward header via ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
jmprusi committed Apr 20, 2018
1 parent 2c6cc8d commit f1090fd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
28 changes: 28 additions & 0 deletions doc/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,31 @@ URI that includes your password and portal endpoint in the following format: `<s
When `THREESCALE_PORTAL_ENDPOINT` environment variable is provided, the gateway will download the configuration from 3scale on initializing. The configuration includes all the settings provided on the Integration page of the API(s).

It is **required** to provide either `THREESCALE_PORTAL_ENDPOINT` or `THREESCALE_CONFIG_FILE` (takes precedence) for the gateway to run successfully.


### `OPENTRACING_TRACER`

**Example** `jaeger`

This environment variable controls which tracing library will be loaded, right now, there's only one opentracing tracer available, `jaeger`.

If empty, opentracing support will be disabled.


### `OPENTRACING_CONFIG`

This environment variable is used to determine the config file for the opentracing tracer, if `OPENTRACING_TRACER` is not set, this variable will be ignored.

Each tracer has a default configuration file:
* `jaeger`: `conf.d/opentracing/jaeger.example.json`

You can choose to mount a different configuration than the provided by default by setting the file path using this variable.

**Example**: `/tmp/jaeger/jaeger.json`

### `OPENTRACING_HEADER_FORWARD`

**Defaul** `uber-trace-id`

This environment variable controls the HTTP header used for forwarding opentracing information, this HTTP header will be forwarded to upstream servers.

12 changes: 11 additions & 1 deletion gateway/conf.d/apicast.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ location = /___http_call {
proxy_set_header User-Agent $user_agent;
proxy_set_header X-3scale-OAuth2-Grant-Type $grant_type;
proxy_set_header 3scale-options $options;
proxy_set_header uber-trace-id $http_uber_trace_id;

# Hack for having a valid openresty config and valid liquid templating
#{% if opentracing_forward_header == nil or opentracing_forward_header == empty %}
# {% assign opentracing_forward_header = "uber-trace-id" %}
#{% endif %}
#{% if opentracing_tracer != nil or opentracing_forward_header != nil %}
# {% capture proxy_set_header_opentracing %}
#{#} proxy_set_header {{opentracing_forward_header}} $http_{{ opentracing_forward_header | replace: "-","_" }};
# {% endcapture %}
# {{ proxy_set_header_opentracing | replace: "#{#}", "" }}
#{% endif %}

rewrite_by_lua_block {
require('resty.http_ng.backend.ngx'):resolver()
Expand Down
7 changes: 6 additions & 1 deletion gateway/conf.d/opentracing/jaeger.conf.liquid
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
opentracing on;
opentracing_load_tracer libjaegertracing.so {{ opentracing_config | default:"conf.d/opentracing/jaeger.example.json"}};

{% if opentracing_config == nil or opentracing_config == empty %}
{% assign opentracing_config = "conf.d/opentracing/jaeger.example.json" %}
{% endif %}

opentracing_load_tracer libjaegertracing.so {{ opentracing_config }};
5 changes: 4 additions & 1 deletion gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ _M.default_environment = 'production'
-- @tfield ?string proxy_ssl_certificate_key path to SSL certificate key
-- @tfield ?string proxy_ssl_session_reuse whether SSL sessions can be reused
-- @tfield ?string proxy_ssl_password_file path to a file with passphrases for the certificate keys
-- @tfield ?string opentracing_tracer loads an opentracing tracer library, for example: jaeger
-- @tfield ?string opentracing_config opentracing config file to load
-- @tfield ?string opentracing_forward_header opentracing http header to forward upstream
-- @tfield ?policy_chain policy_chain @{policy_chain} instance
-- @tfield ?{string,...} nameservers list of nameservers
-- @tfield ?string package.path path to load Lua files
Expand All @@ -103,13 +106,13 @@ _M.default_environment = 'production'

_M.default_config = {
ca_bundle = env_value_ref('SSL_CERT_FILE'),

proxy_ssl_certificate = env_value_ref('APICAST_PROXY_HTTPS_CERTIFICATE'),
proxy_ssl_certificate_key = env_value_ref('APICAST_PROXY_HTTPS_CERTIFICATE_KEY'),
proxy_ssl_session_reuse = env_value_ref('APICAST_PROXY_HTTPS_SESSION_REUSE'),
proxy_ssl_password_file = env_value_ref('APICAST_PROXY_HTTPS_PASSWORD_FILE'),
opentracing_tracer = env_value_ref('OPENTRACING_TRACER'),
opentracing_config = env_value_ref('OPENTRACING_CONFIG'),
opentracing_forward_header = env_value_ref('OPENTRACING_FORWARD_HEADER'),
policy_chain = require('apicast.policy_chain').default(),
nameservers = parse_nameservers(),
worker_processes = cpus() or 'auto',
Expand Down

0 comments on commit f1090fd

Please sign in to comment.