Commit 85daf49
authored
[scraper/scraperhelper] Add scraper ID to error logs (#14461)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
This PR adds the `scraperID` to the error logs for scrapers (metrics,
logs, and profiles). Why is this important?
Currently if an error occurs in any of the scrapers in
`hostmetricsreceiver/internal/scraper/...` there is no info about the
which scraper errored in the logs:
```bash
2026-01-21T10:42:42.830Z error [email protected]/obs_metrics.go:61 Error scraping metrics {"resource": {"service.instance.id": "63071771-056d-40ca-83e3-585dc1a00d57", "service.name": "otelcontribcol", "service.version": "0.144.0-dev"}, "otelcol.component.id": "hostmetrics", "otelcol.component.kind": "receiver", "otelcol.signal": "metrics", "error": "forced test error for scraper identification"}
```
The update in this PR add's the scraper ID (In this case the memory
scraper errored) to the logs which then gives us:
```bash
2026-01-21T10:23:52.759Z error scraperhelper/obs_metrics.go:62 Error scraping metrics {"resource": {"service.instance.id": "7137f19d-706f-4095-8367-0d68b2732402", "service.name": "otelcontribcol", "service.version": "0.144.0-dev"}, "otelcol.component.id": "hostmetrics", "otelcol.component.kind": "receiver", "otelcol.signal": "metrics", "scraper": "memory", "error": "forced test error for scraper identification"}
```
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes Issue in
[collector-contrib](open-telemetry/opentelemetry-collector-contrib#35814 (comment)).
<!--Describe what testing was performed and which tests were added.-->
#### Testing
**Metrics scrapers:** Locally tested with `collector-contrib` by
updating the mod file...
**Logs scrapers:** The same pattern was applied. Logs scrapers (MySQL,
PostgreSQL, Oracle, SQL Server receivers) require database connections
for integration testing.
**Profiles scrapers (xscraperhelper):** The same pattern was applied.
Note: There are currently no profiles scrapers in collector-contrib to
test against.
**Metrics scraper local test**: Locally this was updated and included in
the `collector-contrib` via updating the mod file. An error was forced
in the `hostmetricsreceiver/internal/scraper/...` both memory and cpu,
we can now see which scraper component had an error:
```bash
2026-01-21T11:51:34.176Z error scraperhelper/obs_metrics.go:61 Error scraping metrics {"resource": {"service.instance.id": "e6832705-bc54-43dd-9b1f-0c06d58b7ead", "service.name": "otelcontribcol", "service.version": "0.144.0-dev"}, "otelcol.component.id": "hostmetrics", "otelcol.component.kind": "receiver", "otelcol.signal": "metrics", "scraper": "memory", "error": "forced test error for scraper identification"}
go.opentelemetry.io/collector/scraper/scraperhelper.wrapObsMetrics.func1
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/obs_metrics.go:61
go.opentelemetry.io/collector/scraper.ScrapeMetricsFunc.ScrapeMetrics
/home/dos/go/pkg/mod/go.opentelemetry.io/collector/[email protected]/metrics.go:24
go.opentelemetry.io/collector/scraper/scraperhelper.scrapeMetrics
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/controller.go:167
go.opentelemetry.io/collector/scraper/scraperhelper.NewMetricsController.func1
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/controller.go:139
go.opentelemetry.io/collector/scraper/scraperhelper/internal/controller.(*Controller[...]).startScraping.func1
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/internal/controller/controller.go:118
2026-01-21T11:51:34.177Z error scraperhelper/obs_metrics.go:61 Error scraping metrics {"resource": {"service.instance.id": "e6832705-bc54-43dd-9b1f-0c06d58b7ead", "service.name": "otelcontribcol", "service.version": "0.144.0-dev"}, "otelcol.component.id": "hostmetrics", "otelcol.component.kind": "receiver", "otelcol.signal": "metrics", "scraper": "cpu", "error": "forced test error for scraper identification"}
go.opentelemetry.io/collector/scraper/scraperhelper.wrapObsMetrics.func1
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/obs_metrics.go:61
go.opentelemetry.io/collector/scraper.ScrapeMetricsFunc.ScrapeMetrics
/home/dos/go/pkg/mod/go.opentelemetry.io/collector/[email protected]/metrics.go:24
go.opentelemetry.io/collector/scraper/scraperhelper.scrapeMetrics
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/controller.go:167
go.opentelemetry.io/collector/scraper/scraperhelper.NewMetricsController.func1
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/controller.go:139
go.opentelemetry.io/collector/scraper/scraperhelper/internal/controller.(*Controller[...]).startScraping.func1
/home/dos/Documents/opentelemetry-collector/scraper/scraperhelper/internal/controller/controller.go:118
2026-01-21T11:51:34.199Z info Metrics {"resource": {"service.instance.id": "e6832705-bc54-43dd-9b1f-0c06d58b7ead", "service.name": "otelcontribcol", "service.version": "0.144.0-dev"}, "otelcol.component.id": "debug", "otelcol.component.kind": "exporter", "otelcol.signal": "metrics", "resource metrics": 1, "metrics": 1, "data points": 1}
2026-01-21T11:51:34.199Z info ResourceMetrics #0
Resource SchemaURL: https://opentelemetry.io/schemas/1.9.0
```
Closes
open-telemetry/opentelemetry-collector-contrib#358141 parent c4695a7 commit 85daf49
File tree
6 files changed
+179
-2
lines changed- .chloggen
- scraper/scraperhelper
- internal/controller
- xscraperhelper
6 files changed
+179
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
763 | 765 | | |
764 | 766 | | |
765 | 767 | | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
127 | 131 | | |
128 | | - | |
129 | | - | |
| 132 | + | |
| 133 | + | |
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
22 | 25 | | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
100 | 134 | | |
101 | 135 | | |
102 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
113 | 147 | | |
114 | 148 | | |
115 | 149 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
23 | 26 | | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
115 | 149 | | |
116 | 150 | | |
117 | 151 | | |
| |||
0 commit comments