Skip to content

Commit

Permalink
out_datadog: Add support for setting a static hostname
Browse files Browse the repository at this point in the history
This PR adds support for setting a static hostname in the Datadog output
plugin. This field is analogous to the existing `dd_service` and
`dd_source` configuration options that can be used to set a static
value.

If unset, the default behavior is backwards compatible. This behavior is
to not set an explicity `hostname` field, but if the record has a field
that is detected as the hostname in Datadog (such as `host` or
`syslog.hostname`), it will be picked up.

Closes: #8971

Signed-off-by: Jesse Szwedko <[email protected]>
  • Loading branch information
jszwedko authored and edsiper committed Jun 25, 2024
1 parent d2e01ad commit 1c58785
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/out_datadog/datadog.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ static int datadog_format(struct flb_config *config,
ctx->dd_service, flb_sds_len(ctx->dd_service));
}

/* dd_hostname */
if (ctx->dd_hostname != NULL) {
dd_msgpack_pack_key_value_str(&mp_pck,
FLB_DATADOG_DD_HOSTNAME_KEY,
sizeof(FLB_DATADOG_DD_HOSTNAME_KEY) -1,
ctx->dd_hostname, flb_sds_len(ctx->dd_hostname));
}

/* Append initial object k/v */
ind = 0;
for (i = 0; i < map_size; i++) {
Expand Down Expand Up @@ -514,6 +522,14 @@ static struct flb_config_map config_map[] = {
"The tags you want to assign to your logs in Datadog. If unset, Datadog "
"will expect the tags in the `ddtags` attribute."
},
{
FLB_CONFIG_MAP_STR, "dd_hostname", NULL,
0, FLB_TRUE, offsetof(struct flb_out_datadog, dd_hostname),
"The host that emitted logs should be associated with. If unset, Datadog "
"will expect the host to be set as `host`, `hostname`, or `syslog.hostname` "
"attributes. See Datadog Logs preprocessor documentation for up-to-date "
"of recognized attributes."
},

{
FLB_CONFIG_MAP_STR, "proxy", NULL,
Expand Down
2 changes: 2 additions & 0 deletions plugins/out_datadog/datadog.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define FLB_DATADOG_DEFAULT_PORT 443
#define FLB_DATADOG_DEFAULT_TIME_KEY "timestamp"
#define FLB_DATADOG_DEFAULT_TAG_KEY "tagkey"
#define FLB_DATADOG_DD_HOSTNAME_KEY "hostname"
#define FLB_DATADOG_DD_SOURCE_KEY "ddsource"
#define FLB_DATADOG_DD_SERVICE_KEY "service"
#define FLB_DATADOG_DD_TAGS_KEY "ddtags"
Expand Down Expand Up @@ -65,6 +66,7 @@ struct flb_out_datadog {
int nb_additional_entries;
flb_sds_t dd_source;
flb_sds_t dd_service;
flb_sds_t dd_hostname;
flb_sds_t dd_tags;
flb_sds_t dd_message_key;

Expand Down

0 comments on commit 1c58785

Please sign in to comment.