stderr
and stdout
.
In a typical installation, these will be handled or redirected by the service manager running the process, and depending on the Linux distribution, will either be output to /var/log/
or /var/log/upstart
.
Tyk will try to output structured logs, and so will include context data around request errors where possible.
Custom logging event handlers can be registered against Gateway events to customise the logs that are generated for those events.
When contacting support, you may be asked to change the logging level as part of the support handling process. See Support Information for more details.
error
is the most minimal level of logging, reporting only errors
warn
will log warnings and errors
info
logs errors, warnings and some additional information and is the default logging level
debug
generates a high volume of logs for maximum visibility of what Tyk is doing when you need to debug an issue
--debug
flag to the process run command.log_level
setting in its configuration file (or the equivalent environment variable). Note that there is no independent log level setting for Tyk Dashboard.
Tyk component | Config option | Environment variable | Default value if unset |
---|---|---|---|
All components (except EDP) | TYK_LOGLEVEL | info | |
Tyk Gateway | log_level | TYK_GW_LOGLEVEL | info |
Tyk Pump | log_level | TYK_PMP_LOGLEVEL | info |
Tyk MDCB | log_level | TYK_MDCB_LOGLEVEL | info |
Tyk Enterprise Developer Portal | logLevel | PORTAL_LOG_LEVEL | info |
debug
will enable verbose debug for the Gateway.
Tyk support can advise you which level of verbosity to use for your deployment.
v5.6.0
, you can control the format in which logs will be generated - either default
or json
- using the TYK_LOGFORMAT
environment variable. As a general performance tip, the json
output format incurs less memory allocation overhead than the default
format. For optimal performance, it’s recommended to configure logging in the JSON format.
This is an example of the default
logging format:
json
logging format:
tyk.conf
and your tyk_analytics.conf
:
use_sentry
: Set this to true
to enable the Sentry logger, you must specify a Sentry DSN under sentry_code
.
sentry_code
: The Sentry-assigned DSN (a kind of URL endpoint) that Tyk can send log data to.
tyk.conf
:
use_logstash
: Set this to true
to enable the Logstash logger.
logstash_transport
: The Logstash transport to use, should be "tcp"
.
logstash_network_addr
: Set to the Logstash client network address, should be in the form of hostname:port
.
tyk.conf
:
use_graylog
: Set this to true
to enable the Graylog logger.
graylog_network_addr
: The Graylog client address in the form of <graylog_ip>:<graylog_port>
.
tyk.conf
:
use_syslog
: Set this to true
to enable the Syslog logger.
syslog_transport
: The Syslog transport to use, should be "udp"
or empty.
syslog_network_addr
: Set to the Syslog client network address, should be in the form of hostname:port
TYK_GW_ENABLEANALYTICS
).
The transaction records generated by the Gateway are stored in Redis, from which Tyk Pump can be configured to transfer them to the desired persistent storage. When using Tyk Dashboard, the Aggregate Pump can be used to collate aggregated data that is presented in the analytics screens of the Tyk Dashboard.
The Gateway will not, by default, include the request and response payloads in the transaction records. This minimizes the size of the records and also avoids logging any sensitive content. The detailed recording option is provided if you need to capture the payloads in the records.
You can suppress the generation of transaction records for any endpoint by enabling the do-not-track middleware for that endpoint. This provides granular control over request tracking.
You can find details of all the options available to you when configuring analytics in the Gateway in the reference documentation.
enable_detailed_recording
flag in the root of the API definition.
In the Tyk Classic API Designer, the Enable Detailed Logging option can be found in Core Settings.
spec.enable_detailed_recording
to true
, as in this example:
tyk.conf
.
v5.8.0
, you can configure the Gateway to log individual API request transactions. To enable this feature, set the TYK_GW_ACCESSLOGS_ENABLED
environment variable to true
.
TYK_GW_ACCESSLOGS_TEMPLATE
environment variable. Below are the available values you can include:
api_key
: Obfuscated or hashed API key used in the request.client_ip
: IP address of the client making the request.host
: Hostname of the request.method
: HTTP method used in the request (e.g., GET, POST).path
: URL path of the request.protocol
: Protocol used in the request (e.g., HTTP/1.1).remote_addr
: Remote address of the client.upstream_addr
: Full upstream address including scheme, host, and path.upstream_latency
: Roundtrip duration between the gateway sending the request to the upstream server and it receiving a response.latency_total
: Total time taken for the request, including upstream latency and additional processing by the gateway.user_agent
: User agent string from the client.status
: HTTP response status code.TYK_GW_ACCESSLOGS_TEMPLATE
environment variable with the desired values in the format: ["value1", "value2", ...]
.
tyk.conf
tyk.conf
Key | Analytics aggregated by | Dashboard screen |
---|---|---|
APIID | API proxy | Activity by API |
TrackPath | API endpoint | Activity by endpoint |
ResponseCode | HTTP status code (success/error) | Activity by errors |
APIVersion | API version | n/a |
APIKey | Client access key/token | Activity by Key |
OauthID | OAuth client (if OAuth used) | Traffic per OAuth Client |
Geo | Geographic location of client | Activity by location |
tenant-id=123
user-group=abc
middleware.global
section of the Tyk Vendor Extension, within the trafficLogs
section. Custom aggregation tags are specified as a list of HTTP headers in middleware.global.trafficLogs.tagHeaders that Tyk should use for generation of custom aggregation tags for the API.
For example if we include the header name x-user-id
in the list of headers, then Tyk will create an aggregation key for each different value observed in that header. These aggregation keys will be given the name <header_name>-<header_value>
, for example x-user-id-1234
if the request contains the HTTP header "x-user-id":1234
.
Tyk Classic APIs
If you are using Tyk Classic APIs, then the equivalent field in the API definition is tag_headers.
In the Tyk Classic API Designer, the Tag Headers option can be found in Advanced Options.
spec.tag_headers
to true
, as in this example:
Host
and User-Agent
headers exist within the tag_headers
array. For each incoming request Tyk will add host-<header_value>
and user-agent-<header_value>
tags to the list of tags in the traffic log.
tagHeaders
, you can configure Tyk Pump (or Tyk MDCB if it is performing the pump functionality) to discard those statistics when writing to the persistent analytics store.
For both cases, you simply add the tags you want to ignore, or their prefixes, to the ignore_tag_prefix_list
field in the appropriate configuration file or environment variable:
TYK_INSTRUMENTATION=1
and then configure the statsd_connection_string
field for each component.
statsd_connection_string
is a formatted string that specifies how to connect to the StatsD server. It typically includes information such as the host address, port number, and sometimes additional configuration options.
Optionally you can set statsd_prefix
to a custom prefix value that will be applied to each metric generated by Tyk. For example, you can configure separate prefixes for your production and staging environments to make it easier to differentiate between the metrics in your analysis tool.
gauges.<prefix>.Load.rps
(requests per second)counters.<prefix>.SystemAPICall.called.count
(calls count) and timers.<prefix>.SystemAPICall.success
(response time)counters.<prefix>.SystemAPICall.SystemCallComplete.count
(requests count), counters.<prefix>.DashSystemAPIError.*
(API error reporting)counters.<prefix>.record.count
(number of records processed by pump)tyk.conf
to enable the instrumentation and generation of data:
tyk.conf
):
TYK_GW_OPENTELEMETRY_ENABLED
to true
.
gRPC
protocol to localhost:4317
. You can choose between HTTP and gRPC protocols by configuring the opentelemetry.exporter field to http
or grpc
. You can specify an alternative target using the opentelemetry.endpoint control.tyk.api.name
: API name.tyk.api.orgid
: Organization ID.tyk.api.id
: API ID.tyk.api.path
: API listen path.tyk.api.tags
: If tagging is enabled in the API definition, the tags are added here.Attribute | Type | Description |
---|---|---|
service.name | String | Service name for Tyk API Gateway: tyk-gateway |
service.instance.id and tyk.gw.id | String | The Node ID assigned to the gateway. Example solo-6b71c2de-5a3c-4ad3-4b54-d34d78c1f7a3 |
service.version | String | Represents the service version. Example v5.2.0 |
tyk.gw.dataplane | Bool | Whether the Tyk Gateway is hybrid (slave_options.use_rpc=true ) |
tyk.gw.group.id | String | Represents the slave_options.group_id of the gateway. Populated only if the gateway is hybrid. |
tyk.gw.tags | []String | Represents the gateway segment_tags . Populated only if the gateway is segmented. |
http.method
: HTTP request method.http.scheme
: URL scheme.http.status_code
: HTTP response status code.http.url
: Full HTTP request URL.SpanContext
to/from the B3 multi Headers format. Here you can find more information of this propagator.tracecontext
. To configure this setting, you have two options:
TYK_GW_OPENTELEMETRY_CONTEXTPROPAGATION
to specify the context propagator type.opentelemetry.context_propagation
field in your configuration file to set your preferred option.AlwaysOn
.
To customize, you can either set the TYK_GW_OPENTELEMETRY_SAMPLING_TYPE
environment variable or modify the opentelemetry.sampling.type
field in the Tyk Gateway configuration file. Valid values for this setting are:
Type
is configured to TraceIDRatioBased
. It defines the fraction of traces that OpenTelemetry will aim to sample, and accepts a value between 0.0 and 1.0. For example, a Rate
set to 0.5 implies that approximately 50% of the traces will be sampled. The default value is 0.5. To configure this setting, you have the following options:
TYK_GW_OPENTELEMETRY_SAMPLING_RATE
.opentelemetry.sampling.rate
field in the configuration file.TraceIDRatioBased
, as it helps to keep the entire transaction story together. Using ParentBased
with AlwaysOn
or AlwaysOff
may not be as useful, since in these cases, either all or no spans are sampled. The default value is false
. Configuration options include:
TYK_GW_OPENTELEMETRY_SAMPLING_PARENTBASED
.opentelemetry.sampling.parent_based
field in the configuration file.6c35dacbf2e16aa8cda85a58d9015c3c
.datadoghq.com
, us3.datadoghq.com
and datadoghq.eu
.otel-collector.yml
with the following content:
apps
in the current directory. Create a new file apidef-hello-world.json
and copy this very simple API definition for testing purposes:
docker-compose.yml
.
http://localhost:8080/hello-world/
Next, log in to Datadog and navigate to the ‘APM’ / ‘Traces’ section. Here, you should start observing traces generated by Tyk:
otel-collector-config.yml
. In this file replace <YOUR-ENVIRONMENT-STRING>
with the string from the address bar when you log into Dynatrace. Replace <YOUR-DYNATRACE-API-KEY>
with the token you generated earlier.
Here’s a sample configuration file:
docker-compose logs
<Add your endpoint here>
with the appropriate endpoint from your OpenTelemetry collector.
After enabling OpenTelemetry at the Gateway level, you can activate detailed tracing for specific APIs by editing their respective API definitions. Set the detailed_tracing
option to either true or false. By default, this setting is false.
Profile → API keys
.
INGEST-LICENSE
.
otel-collector-config.yml
under the configs directory.<YOUR-ENVIRONMENT-STRING>
with your specific New Relic endpoint (https://otlp.nr-data.net
for US or https://otlp.eu01.nr-data.net
for EU).<YOUR-NEW-RELIC-API-KEY>
with the API key obtained in Step 1.docker-compose up -d
to start all services.
httpbin
API using Tyk Dashboard. You can follow the Tyk Dashboard documentation for more information.
APM & Services → Services - OpenTelemetry → tyk-gateway
.
apidef-hello-world.json
.apidef-hello-world.json
file:http://httpbin.org/
.
observability
namespace, create a Jaeger instance:jaeger-all-in-one-collector
service.
apidef-hello-world.yaml
:
port-forward command
to access Tyk and Jaeger services running in the cluster from your local machine’s localhost:
For Tyk API Gateway:
http://localhost:16686
, select the ´service´ called ´tyk-gateway´ and click on the button ´Find traces´. You should see traces generated by Tyk:
tyk.conf
file or equivalent environment variables.
name
is the name of the supported tracerenabled
: set this to true to enable tracingoptions
: key/value pairs for configuring the enabled tracer. See the
supported tracer documentation for more details.tyk.conf
on tracing
setting
options
are settings that are used to initialise the Jaeger client. For more details about the options see client libraries
Sample configuration
tyk.conf
under the tracing
section
options
setting you can set the initialisation of the Zipkin client.
Sample configuration
reporter.url
is the URL to the New Relic server, where trace data will be sent to.
tyk.conf
on tracing
setting
options
are settings that are used to initialise the Zipkin client.
Sample configuration
reporter.url
is the URL to the Zipkin server, where trace data will be sent.