-
Notifications
You must be signed in to change notification settings - Fork 38
feat: add configurable transmission delay for metrics #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Angith
wants to merge
14
commits into
main
Choose a base branch
from
configurable-metrics-interval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c1d3317
feat: add configurable transmission delay for metrics
Angith 90fdce5
test: add unit tests for metrics transmission delay
Angith fb07a49
doc: update README, add example for metrics transmission delay
Angith 9698ebd
Merge branch 'main' into configurable-metrics-interval
Angith 3ccdd57
Merge branch 'main' into configurable-metrics-interval
Angith 7bfc771
fix: use constanats for min, max, default transmission intervals
Angith a328ffb
Merge branch 'configurable-metrics-interval' of https://github.com/in…
Angith e0744fd
Merge branch 'main' into configurable-metrics-interval
Angith aec05a0
Merge branch 'main' into configurable-metrics-interval
Angith e234dad
feat: make poll rate retrieval from agent and metrics transmission co…
Angith bd8f1e2
feat: handle metrics collection logic on agent reset
Angith 4f5c4f3
chore: code cleanup
Angith b68cba7
fix: cuncurrent access of stop and run
Angith 81afc08
fix: resolve metrics collection issue for serverless agent
Angith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Configurable Metrics Transmission Interval Examples | ||
|
|
||
| This directory contains examples demonstrating how to configure the metrics transmission interval in the Instana Go Sensor. | ||
|
|
||
| ## Overview | ||
|
|
||
| The Instana Go Sensor allows you to configure how frequently metrics are transmitted to the Instana agent. By default, metrics are sent every 1000ms (1 second), but this can be customized based on your application's needs. | ||
|
|
||
| ## Configuration Methods | ||
|
|
||
| ### 1. Environment Variable (env-config/) | ||
|
|
||
| Configure the interval using the `INSTANA_METRICS_TRANSMISSION_DELAY` environment variable. | ||
|
|
||
| ```bash | ||
| export INSTANA_METRICS_TRANSMISSION_DELAY=2000 | ||
| go run example/metrics-interval/env-config/main.go | ||
| ``` | ||
|
|
||
| **Advantages:** | ||
| - No code changes required | ||
| - Easy to adjust per environment (dev, staging, prod) | ||
| - Takes precedence over code configuration | ||
|
|
||
| ### 2. Code Configuration (code-config/) | ||
|
|
||
| Configure the interval programmatically in your application code. | ||
|
|
||
| ```go | ||
| instana.InitCollector(&instana.Options{ | ||
| Service: "my-service", | ||
| Metrics: instana.MetricsOptions{ | ||
| TransmissionDelay: 3000, // 3 seconds | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| **Advantages:** | ||
| - Explicit and visible in code | ||
| - Can be set conditionally based on application logic | ||
| - Type-safe configuration | ||
|
|
||
| ## Configuration Rules | ||
|
|
||
| - **Valid Range**: 1000ms to 5000ms | ||
| - **Default**: 1000ms (if not specified or invalid) | ||
| - **Maximum Cap**: Values above 5000ms are automatically capped at 5000ms | ||
| - **Invalid Values**: Non-numeric, zero, or negative values fall back to default 1000ms | ||
| - **Precedence**: Environment variable > Code configuration > Default | ||
|
|
||
| ## Running the Examples | ||
|
|
||
| ### Environment Variable Example | ||
| environment variable is set programmatically in the code. | ||
| ```bash | ||
| cd example/metrics-interval/env-config | ||
| go run main.go | ||
| ``` | ||
|
|
||
| ### Code Configuration Example | ||
| ```bash | ||
| cd example/metrics-interval/code-config | ||
| go run main.go | ||
| ``` | ||
|
|
||
| ## Validation and Error Handling | ||
|
|
||
| The sensor validates all configuration values and provides warning logs for invalid inputs: | ||
|
|
||
| - **Invalid format**: Falls back to default 1000ms with warning | ||
| - **Out of range**: Caps at 5000ms or uses default for values ≤ 1000 | ||
| - **Graceful degradation**: Application continues running with safe defaults | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Main Documentation](../../README.md) | ||
| - [Options Documentation](../../docs/options.md) | ||
| - [Instana Go Sensor API](https://pkg.go.dev/github.com/instana/go-sensor) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // SPDX-FileCopyrightText: 2026 IBM Corp. | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
| "os/signal" | ||
| "time" | ||
|
|
||
| instana "github.com/instana/go-sensor" | ||
| ) | ||
|
|
||
| func main() { | ||
| fmt.Println("=== Instana Metrics Transmission Interval - Code Configuration ===") | ||
| fmt.Println() | ||
|
|
||
| // Example 1: Configure metrics transmission interval via code | ||
| fmt.Println("Example 1: Setting custom interval to 3000ms (3 seconds)") | ||
|
|
||
| opts := &instana.Options{ | ||
| Service: "metrics-interval-code-example-2", | ||
| Metrics: instana.MetricsOptions{ | ||
| TransmissionDelay: 3000, // 3000 milliseconds = 3 seconds | ||
| }, | ||
| } | ||
|
|
||
| col := instana.InitCollector(opts) | ||
|
|
||
| fmt.Println("✓ Instana collector initialized") | ||
| fmt.Println("✓ Metrics will be transmitted every 3000ms") | ||
| fmt.Println() | ||
|
|
||
| // Example 2: Different configurations | ||
| fmt.Println("Other configuration examples:") | ||
| fmt.Println() | ||
|
|
||
| // Fast interval for high-frequency monitoring | ||
| fmt.Println(" Fast interval (500ms):") | ||
| fmt.Println(" Metrics: instana.MetricsOptions{") | ||
| fmt.Println(" TransmissionDelay: 500,") | ||
| fmt.Println(" }") | ||
| fmt.Println() | ||
|
|
||
| // Slow interval for resource-constrained environments | ||
| fmt.Println(" Slow interval (5000ms - maximum):") | ||
| fmt.Println(" Metrics: instana.MetricsOptions{") | ||
| fmt.Println(" TransmissionDelay: 5000,") | ||
| fmt.Println(" }") | ||
| fmt.Println() | ||
|
|
||
| // Default behavior | ||
| fmt.Println(" Default interval (1000ms):") | ||
| fmt.Println(" Metrics: instana.MetricsOptions{") | ||
| fmt.Println(" TransmissionDelay: 0, // or omit the field") | ||
| fmt.Println(" }") | ||
| fmt.Println() | ||
|
|
||
| fmt.Println("Configuration rules:") | ||
| fmt.Println(" - Valid range: 1ms to 5000ms") | ||
| fmt.Println(" - Values above 5000ms are automatically capped at 5000ms") | ||
| fmt.Println(" - Zero or negative values use default 1000ms") | ||
| fmt.Println(" - Environment variable INSTANA_METRICS_TRANSMISSION_DELAY takes precedence") | ||
| fmt.Println() | ||
|
|
||
| // Simulate application running | ||
| go func() { | ||
| http.HandleFunc("/endpoint", instana.TracingHandlerFunc(col, "/endpoint", func(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| })) | ||
|
|
||
| log.Fatal(http.ListenAndServe(":7070", nil)) | ||
| }() | ||
|
|
||
| go func() { | ||
| ticker := time.NewTicker(5 * time.Second) | ||
|
|
||
| client := &http.Client{ | ||
| Timeout: 10 * time.Second, | ||
| } | ||
|
|
||
| for range ticker.C { | ||
| url := "http://localhost:7070/endpoint" | ||
| // Create request | ||
| req, err := http.NewRequest(http.MethodGet, url, nil) | ||
| if err != nil { | ||
| fmt.Println("Error creating request:", err) | ||
| return | ||
| } | ||
| // Send request | ||
| _, err = client.Do(req) | ||
| if err != nil { | ||
| fmt.Println("Error making request:", err) | ||
| return | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| fmt.Println("Please go to the Instana UI to see metrics") | ||
| fmt.Println("Application running... (press Ctrl+C to exit)") | ||
|
|
||
| stop := make(chan os.Signal, 1) | ||
| signal.Notify(stop, os.Interrupt) | ||
| <-stop | ||
| fmt.Println("Application stopped.") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // SPDX-FileCopyrightText: 2026 IBM Corp. | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
| "os/signal" | ||
| "time" | ||
|
|
||
| instana "github.com/instana/go-sensor" | ||
| ) | ||
|
|
||
| func main() { | ||
| // Example: Configure metrics transmission interval via environment variable | ||
| // Set INSTANA_METRICS_TRANSMISSION_DELAY before starting the application | ||
|
|
||
| // For demonstration, we'll set it programmatically here | ||
| // In production, set this via your deployment configuration | ||
| os.Setenv("INSTANA_METRICS_TRANSMISSION_DELAY", "2000") | ||
|
|
||
| fmt.Println("=== Instana Metrics Transmission Interval - ENV Configuration ===") | ||
| fmt.Println() | ||
| fmt.Println("Environment variable INSTANA_METRICS_TRANSMISSION_DELAY=2000") | ||
| fmt.Println("This will configure metrics to be transmitted every 2000ms (2 seconds)") | ||
| fmt.Println() | ||
|
|
||
| // Initialize the Instana collector with default options | ||
| // The environment variable will be automatically applied | ||
| col := instana.InitCollector(&instana.Options{ | ||
| Service: "metrics-interval-env-example", | ||
| }) | ||
|
|
||
| fmt.Println("✓ Instana collector initialized") | ||
| fmt.Println("✓ Metrics will be transmitted every 2000ms") | ||
| fmt.Println() | ||
| fmt.Println("Valid values:") | ||
| fmt.Println(" - Minimum: 1ms") | ||
| fmt.Println(" - Maximum: 5000ms (values above will be capped)") | ||
| fmt.Println(" - Default: 1000ms (if not specified or invalid)") | ||
| fmt.Println() | ||
| fmt.Println("Invalid values (non-numeric, negative, zero) will fall back to default 1000ms") | ||
| fmt.Println() | ||
|
|
||
| // Simulate application running | ||
| go func() { | ||
| http.HandleFunc("/endpoint", instana.TracingHandlerFunc(col, "/endpoint", func(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| })) | ||
|
|
||
| log.Fatal(http.ListenAndServe(":7070", nil)) | ||
| }() | ||
|
|
||
| go func() { | ||
| ticker := time.NewTicker(5 * time.Second) | ||
|
|
||
| client := &http.Client{ | ||
| Timeout: 10 * time.Second, | ||
| } | ||
|
|
||
| for range ticker.C { | ||
| url := "http://localhost:7070/endpoint" | ||
| // Create request | ||
| req, err := http.NewRequest(http.MethodGet, url, nil) | ||
| if err != nil { | ||
| fmt.Println("Error creating request:", err) | ||
| return | ||
| } | ||
| // Send request | ||
| _, err = client.Do(req) | ||
| if err != nil { | ||
| fmt.Println("Error making request:", err) | ||
| return | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| fmt.Println("Please go to the Instana UI to see metrics") | ||
| fmt.Println("Application running... (press Ctrl+C to exit)") | ||
| stop := make(chan os.Signal, 1) | ||
| signal.Notify(stop, os.Interrupt) | ||
| <-stop | ||
| fmt.Println("Application stopped.") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.