Skip to content

Commit dd1e8cf

Browse files
committed
[processor/geoipprocessor] Read both the client.address and the source.address attributes
1 parent 22cd8a2 commit dd1e8cf

File tree

9 files changed

+483
-4
lines changed

9 files changed

+483
-4
lines changed

processor/geoipprocessor/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
## Description
1616

17-
The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes using the [`source.address` semantic conventions key attribute](https://github.com/open-telemetry/semantic-conventions/blob/v1.26.0/docs/general/attributes.md#source). By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec.
17+
The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes using the [`client.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#client-attributes) or the [`source.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#source) semantic conventions key attribute. By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec.
1818

1919
### Geographical location metadata
2020

processor/geoipprocessor/factory.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ var (
2424
// defaultResourceAttributes holds a list of default resource attribute keys.
2525
// These keys are used to identify an IP address attribute associated with the resource.
2626
defaultResourceAttributes = []attribute.Key{
27-
semconv.SourceAddressKey, // This key represents the standard source address attribute as defined in the OpenTelemetry semantic conventions.
27+
// The client attributes are in use by the HTTP semantic conventions
28+
semconv.ClientAddressKey,
29+
// The source attributes are used when there is no client/server relationship between the two sides, or when that relationship is unknown
30+
semconv.SourceAddressKey,
2831
}
2932
)
3033

processor/geoipprocessor/geoip_processor_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"go.opentelemetry.io/collector/processor"
1616
"go.opentelemetry.io/collector/processor/processortest"
1717
"go.opentelemetry.io/otel/attribute"
18-
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
1918

2019
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
2120
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/plogtest"
@@ -121,6 +120,11 @@ var testCases = []struct {
121120
goldenDir: "attribute_source_address",
122121
context: record,
123122
},
123+
{
124+
name: "client address located in inner attributes",
125+
goldenDir: "attribute_client_address",
126+
context: record,
127+
},
124128
}
125129

126130
func compareAllSignals(cfg component.Config, goldenDir string) func(t *testing.T) {
@@ -197,7 +201,6 @@ func TestProcessor(t *testing.T) {
197201
baseProviderMock.LocationF = func(_ context.Context, sourceIP net.IP) (attribute.Set, error) {
198202
if sourceIP.Equal(net.IPv4(1, 2, 3, 4)) {
199203
return attribute.NewSet([]attribute.KeyValue{
200-
semconv.SourceAddress("1.2.3.4"),
201204
attribute.String(conventions.AttributeGeoCityName, "Boxford"),
202205
attribute.String(conventions.AttributeGeoContinentCode, "EU"),
203206
attribute.String(conventions.AttributeGeoContinentName, "Europe"),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resourceLogs:
2+
- resource:
3+
attributes:
4+
- key: ip
5+
value:
6+
stringValue: 1.2.2.1
7+
scopeLogs:
8+
- logRecords:
9+
- attributes:
10+
- key: client.address
11+
value:
12+
stringValue: 1.2.3.4
13+
- key: host.name
14+
value:
15+
stringValue: HOST.ONE
16+
- key: log.file.name
17+
value:
18+
stringValue: one.log
19+
body:
20+
stringValue: hello one
21+
spanId: ""
22+
traceId: ""
23+
scope: {}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
resourceMetrics:
2+
- resource:
3+
attributes:
4+
- key: ip
5+
value:
6+
stringValue: 1.2.2.1
7+
schemaUrl: https://test-res-schema.com/schema
8+
scopeMetrics:
9+
- metrics:
10+
- description: This also isn't a real metric
11+
name: storage.amplitude
12+
sum:
13+
aggregationTemporality: 2
14+
dataPoints:
15+
- asInt: "0"
16+
attributes:
17+
- key: a
18+
value:
19+
stringValue: AAAA
20+
- key: client.address
21+
value:
22+
stringValue: 1.2.3.4
23+
isMonotonic: false
24+
unit: "1"
25+
- name: delta.histogram.test
26+
histogram:
27+
aggregationTemporality: 1
28+
dataPoints:
29+
- explicitBounds: [0.01, 0.1, 1, 10, 100]
30+
timeUnixNano: "1000000"
31+
bucketCounts: [9, 12, 17, 8, 34]
32+
attributes:
33+
- key: client.address
34+
value:
35+
stringValue: 1.2.3.4
36+
- name: summary.test
37+
summary:
38+
dataPoints:
39+
- timeUnixNano: "1000000"
40+
quantileValues:
41+
- quantile: 0.25
42+
value: 50
43+
- quantile: 0.5
44+
value: 20
45+
- quantile: 0.75
46+
value: 75
47+
- quantile: 0.95
48+
value: 10
49+
attributes:
50+
- key: client.address
51+
value:
52+
stringValue: 1.2.3.4
53+
- gauge:
54+
dataPoints:
55+
- asDouble: 345
56+
attributes:
57+
- key: client.address
58+
value:
59+
stringValue: 1.2.3.4
60+
- key: aaa
61+
value:
62+
stringValue: bbb
63+
timeUnixNano: "1000000"
64+
name: test.gauge
65+
schemaUrl: https://test-scope-schema.com/schema
66+
scope:
67+
attributes:
68+
- key: foo
69+
value:
70+
stringValue: bar
71+
name: MyTestInstrument
72+
version: 1.2.3
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
resourceSpans:
2+
- resource:
3+
attributes:
4+
scopeSpans:
5+
- scope: {}
6+
spans:
7+
- attributes:
8+
- key: http.request.method
9+
value:
10+
stringValue: POST
11+
- key: url.full
12+
value:
13+
stringValue: https://www.foo.bar/search?q=OpenTelemetry#SemConv
14+
- key: http.response.status_code
15+
value:
16+
intValue: "201"
17+
- key: ip
18+
value:
19+
stringValue: 1.2.2.1
20+
- key: client.address
21+
value:
22+
stringValue: 1.2.3.4
23+
endTimeUnixNano: "1581452773000000789"
24+
events:
25+
- attributes:
26+
- key: event.attr1
27+
value:
28+
stringValue: foo2
29+
- key: event.attr2
30+
value:
31+
stringValue: bar2
32+
name: event2
33+
timeUnixNano: "1581452773000000123"
34+
name: span-elastic-http
35+
parentSpanId: bcff497b5a47310f
36+
spanId: ""
37+
startTimeUnixNano: "1581452772000000321"
38+
status: {}
39+
traceId: ""
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
resourceLogs:
2+
- resource:
3+
attributes:
4+
- key: ip
5+
value:
6+
stringValue: 1.2.2.1
7+
scopeLogs:
8+
- logRecords:
9+
- attributes:
10+
- key: client.address
11+
value:
12+
stringValue: 1.2.3.4
13+
- key: host.name
14+
value:
15+
stringValue: HOST.ONE
16+
- key: log.file.name
17+
value:
18+
stringValue: one.log
19+
- key: geo.city_name
20+
value:
21+
stringValue: Boxford
22+
- key: geo.continent_code
23+
value:
24+
stringValue: EU
25+
- key: geo.continent_name
26+
value:
27+
stringValue: Europe
28+
- key: geo.country_iso_code
29+
value:
30+
stringValue: GB
31+
- key: geo.country_name
32+
value:
33+
stringValue: United Kingdom
34+
- key: geo.location.lat
35+
value:
36+
doubleValue: 1234
37+
- key: geo.location.lon
38+
value:
39+
doubleValue: 5678
40+
- key: geo.postal_code
41+
value:
42+
stringValue: OX1
43+
- key: geo.region_iso_code
44+
value:
45+
stringValue: WBK
46+
- key: geo.region_name
47+
value:
48+
stringValue: West Berkshire
49+
- key: geo.timezone
50+
value:
51+
stringValue: Europe/London
52+
body:
53+
stringValue: hello one
54+
spanId: ""
55+
traceId: ""
56+
scope: {}

0 commit comments

Comments
 (0)