Skip to content

fix(serverless-init): set serverless log hostname to empty string#40074

Merged
dd-mergequeue[bot] merged 7 commits into
mainfrom
duncan-harvey/serverless-init-logs-host-empty-string
Aug 25, 2025
Merged

fix(serverless-init): set serverless log hostname to empty string#40074
dd-mergequeue[bot] merged 7 commits into
mainfrom
duncan-harvey/serverless-init-logs-host-empty-string

Conversation

@duncanpharvey

@duncanpharvey duncanpharvey commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Passes the hostnameinterface component to the Serverless Logs Agent so the hostname on logs is set to an empty string.

Motivation

https://datadoghq.atlassian.net/browse/SVLS-7460

Currently the hostname is being set to unknown. In Datadog Orgs where a host with the name unknown already exists and has tags on it, logs with a matching hostname will inherit these tags, potentially resulting in scenarios where a log has multiple tags with the same key but different values.

Describe how you validated your changes

Added a serverless-init log test to validate that the hostname component has an empty string set for a build of serverless-init.

Also deployed manually to Google Cloud Run and Azure Container Apps using both the sidecar and in process approach to validate the logs have hostname set as an empty string.

Possible Drawbacks / Trade-offs

Additional Notes

A regression was introduced in v1.2.1 of the serverless-init image that caused the hostname to be set to unknown. It's unclear what specific change caused the regression as no Github tags were created for these older versions.

There is already a provider hostname configuration for Serverless. By passing the hostnameinterface component to the Serverless Logs Agent we can set the empty string hostname on the provider.

Ultimately the hostname is passed to the logs processor where it is read and inserted into the log message. This is where the hostname was set to unknown prior to this change.

// GetHostname returns the hostname to applied the given log message
func (p *Processor) GetHostname(msg *message.Message) string {
if msg.Hostname != "" {
return msg.Hostname
}
if msg.Lambda != nil {
return msg.Lambda.ARN
}
if p.hostname == nil {
return "unknown"
}
hname, err := p.hostname.Get(context.TODO())
if err != nil {
// this scenario is not likely to happen since
// the agent cannot start without a hostname
hname = "unknown"
}
return hname
}

Since the signature of SetupLogAgent is updated to include the hostname component cmd/serverless needs to be updated as well. However Lambda Functions have special handling in the logs processor which means this change will not affect the hostname on Lambda Function logs.

func SetupLogAgent(conf *Config, tags map[string]string, tagger tagger.Component, compression logscompression.Component, hostname hostnameinterface.Component, origin string) logsAgent.ServerlessLogsAgent {

@github-actions github-actions Bot added the medium review PR review might take time label Aug 20, 2025
@cit-pr-commenter

cit-pr-commenter Bot commented Aug 20, 2025

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: f8ec604e-0527-44e8-8b6b-738ea40184ab

Baseline: fb444b5
Comparison: 42a25bb
Diff

Optimization Goals: ✅ No significant changes detected

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization +0.98 [-2.08, +4.05] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
tcp_syslog_to_blackhole ingress throughput +1.10 [+1.02, +1.19] 1 Logs
docker_containers_cpu % cpu utilization +0.98 [-2.08, +4.05] 1 Logs
quality_gate_logs % cpu utilization +0.81 [-1.92, +3.53] 1 Logs bounds checks dashboard
quality_gate_metrics_logs memory utilization +0.68 [+0.29, +1.08] 1 Logs bounds checks dashboard
ddot_logs memory utilization +0.31 [+0.22, +0.40] 1 Logs
ddot_metrics memory utilization +0.26 [+0.15, +0.37] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.10 [-0.48, +0.68] 1 Logs
file_to_blackhole_1000ms_latency egress throughput +0.01 [-0.59, +0.62] 1 Logs
file_to_blackhole_100ms_latency egress throughput +0.01 [-0.59, +0.61] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.00 [-0.28, +0.28] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.02, +0.01] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.01 [-0.07, +0.05] 1 Logs
file_tree memory utilization -0.04 [-0.07, -0.00] 1 Logs
quality_gate_idle_all_features memory utilization -0.04 [-0.08, -0.01] 1 Logs bounds checks dashboard
file_to_blackhole_500ms_latency egress throughput -0.06 [-0.65, +0.52] 1 Logs
otlp_ingest_metrics memory utilization -0.13 [-0.27, +0.02] 1 Logs
otlp_ingest_logs memory utilization -0.16 [-0.28, -0.03] 1 Logs
quality_gate_idle memory utilization -0.21 [-0.25, -0.18] 1 Logs bounds checks dashboard
docker_containers_memory memory utilization -0.27 [-0.32, -0.23] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
docker_containers_cpu simple_check_run 10/10
docker_containers_memory memory_usage 10/10
docker_containers_memory simple_check_run 10/10
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle intake_connections 10/10 bounds checks dashboard
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs intake_connections 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_logs memory_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 bounds checks dashboard
quality_gate_metrics_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.

@duncanpharvey
duncanpharvey force-pushed the duncan-harvey/serverless-init-logs-host-empty-string branch 4 times, most recently from 8617a7f to 06a65c4 Compare August 20, 2025 23:29
@duncanpharvey
duncanpharvey force-pushed the duncan-harvey/serverless-init-logs-host-empty-string branch from 06a65c4 to 9532089 Compare August 21, 2025 00:16
@agent-platform-auto-pr

agent-platform-auto-pr Bot commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor fb444b5

Successful checks

Info

Quality gate Delta On disk size (MiB) Delta On wire size (MiB)
agent_deb_amd64 $${-0}$$ $${701.41}$$ < $${704.84}$$ $${-0.01}$$ $${177.61}$$ < $${178.58}$$
agent_deb_amd64_fips $${-0}$$ $${688.69}$$ < $${703.09}$$ $${+0.01}$$ $${174.54}$$ < $${178.12}$$
agent_heroku_amd64 $${0}$$ $${350.92}$$ < $${355.37}$$ $${+0}$$ $${94.61}$$ < $${95.72}$$
agent_msi $${0}$$ $${974.61}$$ < $${980.61}$$ $${0}$$ $${147.39}$$ < $${149.31}$$
agent_rpm_amd64 $${-0}$$ $${701.4}$$ < $${704.83}$$ $${-0.03}$$ $${179.86}$$ < $${180.22}$$
agent_rpm_amd64_fips $${-0}$$ $${688.68}$$ < $${703.08}$$ $${+0}$$ $${176.04}$$ < $${179.85}$$
agent_rpm_arm64 $${+0}$$ $${690.34}$$ < $${694.74}$$ $${+0}$$ $${162.15}$$ < $${163.96}$$
agent_rpm_arm64_fips $${+0}$$ $${678.46}$$ < $${693.05}$$ $${+0.03}$$ $${158.78}$$ < $${163.0}$$
agent_suse_amd64 $${-0}$$ $${701.4}$$ < $${704.83}$$ $${-0.03}$$ $${179.86}$$ < $${180.22}$$
agent_suse_amd64_fips $${-0}$$ $${688.68}$$ < $${703.08}$$ $${+0}$$ $${176.04}$$ < $${179.85}$$
agent_suse_arm64 $${+0}$$ $${690.34}$$ < $${694.74}$$ $${+0}$$ $${162.15}$$ < $${163.96}$$
agent_suse_arm64_fips $${+0}$$ $${678.46}$$ < $${693.05}$$ $${+0.03}$$ $${158.78}$$ < $${163.0}$$
docker_agent_amd64 $${-0}$$ $${783.39}$$ < $${788.65}$$ $${+0}$$ $${270.01}$$ < $${272.01}$$
docker_agent_arm64 $${+0}$$ $${795.66}$$ < $${802.0}$$ $${+0}$$ $${256.77}$$ < $${259.7}$$
docker_agent_jmx_amd64 $${-0}$$ $${974.69}$$ < $${979.84}$$ $${-0}$$ $${339.05}$$ < $${340.95}$$
docker_agent_jmx_arm64 $${+0}$$ $${975.56}$$ < $${981.8}$$ $${-0}$$ $${321.8}$$ < $${324.65}$$
docker_cluster_agent_amd64 $${-0}$$ $${211.87}$$ < $${214.5}$$ $${-0}$$ $${72.04}$$ < $${73.51}$$
docker_cluster_agent_arm64 $${+0}$$ $${227.86}$$ < $${230.33}$$ $${+0}$$ $${68.34}$$ < $${69.77}$$
docker_cws_instrumentation_amd64 $${0}$$ $${7.07}$$ < $${7.12}$$ $${0}$$ $${2.95}$$ < $${3.29}$$
docker_cws_instrumentation_arm64 $${0}$$ $${6.69}$$ < $${6.92}$$ $${-0}$$ $${2.7}$$ < $${3.07}$$
docker_dogstatsd_amd64 $${0}$$ $${38.58}$$ < $${39.57}$$ $${+0}$$ $${14.91}$$ < $${15.76}$$
docker_dogstatsd_arm64 $${+0}$$ $${37.23}$$ < $${38.2}$$ $${+0}$$ $${14.36}$$ < $${14.83}$$
dogstatsd_deb_amd64 $${0}$$ $${29.82}$$ < $${31.4}$$ $${+0}$$ $${7.86}$$ < $${8.95}$$
dogstatsd_deb_arm64 $${0}$$ $${28.4}$$ < $${29.97}$$ $${+0}$$ $${6.83}$$ < $${7.89}$$
dogstatsd_rpm_amd64 $${0}$$ $${29.82}$$ < $${31.4}$$ $${+0}$$ $${7.87}$$ < $${8.96}$$
dogstatsd_suse_amd64 $${0}$$ $${29.82}$$ < $${31.4}$$ $${+0}$$ $${7.87}$$ < $${8.96}$$
iot_agent_deb_amd64 $${0}$$ $${54.22}$$ < $${54.55}$$ $${-0}$$ $${13.66}$$ < $${14.45}$$
iot_agent_deb_arm64 $${0}$$ $${51.54}$$ < $${51.9}$$ $${-0}$$ $${11.83}$$ < $${12.63}$$
iot_agent_deb_armhf $${0}$$ $${51.09}$$ < $${51.42}$$ $${+0.01}$$ $${11.89}$$ < $${12.74}$$
iot_agent_rpm_amd64 $${0}$$ $${54.22}$$ < $${54.55}$$ $${+0}$$ $${13.68}$$ < $${14.47}$$
iot_agent_suse_amd64 $${0}$$ $${54.22}$$ < $${54.55}$$ $${+0}$$ $${13.68}$$ < $${14.47}$$

@github-actions

Copy link
Copy Markdown
Contributor

Serverless Benchmark Results

BenchmarkStartEndInvocation comparison between 05d5dbc and bc412627fecb54385f4ad76f9791d60c5ddf1fa9.

tl;dr

Use these benchmarks as an insight tool during development.

  1. Skim down the vs base column in each chart. If there is a ~, then there was no statistically significant change to the benchmark. Otherwise, ensure the estimated percent change is either negative or very small.

  2. The last row of each chart is the geomean. Ensure this percentage is either negative or very small.

What is this benchmarking?

The BenchmarkStartEndInvocation compares the amount of time it takes to call the start-invocation and end-invocation endpoints. For universal instrumentation languages (Dotnet, Golang, Java, Ruby), this represents the majority of the duration overhead added by our tracing layer.

The benchmark is run using a large variety of lambda request payloads. In the charts below, there is one row for each event payload type.

How do I interpret these charts?

The charts below comes from benchstat. They represent the statistical change in duration (sec/op), memory overhead (B/op), and allocations (allocs/op).

The benchstat docs explain how to interpret these charts.

Before the comparison table, we see common file-level configuration. If there are benchmarks with different configuration (for example, from different packages), benchstat will print separate tables for each configuration.

The table then compares the two input files for each benchmark. It shows the median and 95% confidence interval summaries for each benchmark before and after the change, and an A/B comparison under "vs base". ... The p-value measures how likely it is that any differences were due to random chance (i.e., noise). The "~" means benchstat did not detect a statistically significant difference between the two inputs. ...

Note that "statistically significant" is not the same as "large": with enough low-noise data, even very small changes can be distinguished from noise and considered statistically significant. It is, of course, generally easier to distinguish large changes from noise.

Finally, the last row of the table shows the geometric mean of each column, giving an overall picture of how the benchmarks changed. Proportional changes in the geomean reflect proportional changes in the benchmarks. For example, given n benchmarks, if sec/op for one of them increases by a factor of 2, then the sec/op geomean will increase by a factor of ⁿ√2.

I need more help

First off, do not worry if the benchmarks are failing. They are not tests. The intention is for them to be a tool for you to use during development.

If you would like a hand interpreting the results come chat with us in #serverless-agent in the internal DataDog slack or in #serverless in the public DataDog slack. We're happy to help!

Benchmark stats

@agent-platform-auto-pr

Copy link
Copy Markdown
Contributor

Gitlab CI Configuration Changes

Added Jobs

tests_serverless-init-logs
tests_serverless-init-logs:
  image: registry.ddbuild.io/ci/datadog-agent-buildimages/linux$CI_IMAGE_LINUX_SUFFIX:$CI_IMAGE_LINUX
  needs:
  - go_deps
  rules:
  - if: $RUN_UNIT_TESTS == "off"
    when: never
  - if: $CI_COMMIT_BRANCH =~ /^mq-working-branch-/
    when: never
  - when: on_success
  script:
  - mkdir -p $GOPATH/pkg/mod/cache && tar xJf modcache.tar.xz -C $GOPATH/pkg/mod/cache
    || exit 101
  - rm -f modcache.tar.xz
  - go test -tags "serverless otlp test" ./cmd/serverless-init/.
  stage: source_test
  tags:
  - arch:amd64

Changes Summary

Removed Modified Added Renamed
0 0 1 0

ℹ️ Diff available in the job log.

@duncanpharvey duncanpharvey added qa/done QA done before merge and regressions are covered by tests changelog/no-changelog No changelog entry needed labels Aug 21, 2025
@duncanpharvey
duncanpharvey marked this pull request as ready for review August 22, 2025 17:12
@duncanpharvey
duncanpharvey requested review from a team as code owners August 22, 2025 17:12

@jszwedko jszwedko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for @DataDog/agent-log-pipelines owned files. Generally this approach makes sense to me to avoid having host set to unknown.

@duncanpharvey duncanpharvey changed the title fix(serverless-init): set serverless log host to empty string fix(serverless-init): set serverless log hostname to empty string Aug 22, 2025
@duncanpharvey

Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Aug 25, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-08-25 18:08:12 UTC ℹ️ Start processing command /merge


2025-08-25 18:08:20 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 38m (p90).


2025-08-25 18:32:14 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit fb68968 into main Aug 25, 2025
366 of 369 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the duncan-harvey/serverless-init-logs-host-empty-string branch August 25, 2025 18:32
@github-actions github-actions Bot added this to the 7.71.0 milestone Aug 25, 2025
@ylee-figma

Copy link
Copy Markdown

Hello! I was curious when this version would be released? I hit this issue recently and I've verified using 1.1.4 does indeed not cause tag inheritance behavior as described. I'd also prefer to not use a quite outdated version of serverless-init (1.1.4 looks like it's 2 years old). Thanks!

@ylee-figma

ylee-figma commented Aug 26, 2025

Copy link
Copy Markdown

@duncanpharvey

Copy link
Copy Markdown
Contributor Author

Hi @ylee-figma! serverless-init-1.7.9 was released this morning to Docker, ECR, and GAR.

@SamuelMS

SamuelMS commented Sep 2, 2025

Copy link
Copy Markdown

@duncanpharvey Is there a way to specifically set hostname, rather than it always being blank or unknown, e.g. when following datadog's Azure Container Apps guide for serverless-init? We've got concrete hostnames in this case and would want to use the per-replica variant instead (e.g. CONTAINER_APP_REPLICA_NAME in the ACA docs).

@duncanpharvey

Copy link
Copy Markdown
Contributor Author

Hi @SamuelMS!

A Github issue was recently opened for this and we created a Feature Request on our side. However we don't currently have any estimates for when that feature request may be addressed.

#39536

@SamuelMS

SamuelMS commented Sep 3, 2025

Copy link
Copy Markdown

Hi @SamuelMS!

A Github issue was recently opened for this and we created a Feature Request on our side. However we don't currently have any estimates for when that feature request may be addressed.

#39536

Thanks for the reply; I'll drop a message in #39536 as well to share this same context, since this is a meaningful improvement for ACA customers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed medium review PR review might take time qa/done QA done before merge and regressions are covered by tests team/serverless-azure-gcp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants