Skip to content

Commit 075d946

Browse files
authored
Merge branch 'main' into update_user_events_deps
2 parents 0f62386 + 4421243 commit 075d946

File tree

5 files changed

+147
-6
lines changed

5 files changed

+147
-6
lines changed

.github/workflows/nginx.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
name: nginx instrumentation CI
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches: "*"
67
paths:
78
- 'instrumentation/nginx/**'
89
- '.github/workflows/nginx.yml'
10+
tags:
11+
- 'nginx/*'
912
pull_request:
10-
branches: [ main ]
13+
branches: [main]
1114
paths:
1215
- 'instrumentation/nginx/**'
1316
- '.github/workflows/nginx.yml'
14-
1517
jobs:
18+
create-release:
19+
if: startsWith(github.ref, 'refs/tags/nginx')
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Release
23+
uses: softprops/action-gh-release@v2
24+
upload-release-artifacts:
25+
if: startsWith(github.ref, 'refs/tags/nginx')
26+
runs-on: ubuntu-latest
27+
needs: [nginx-build-test, create-release]
28+
steps:
29+
- name: Create directory
30+
run: |
31+
mkdir artifacts
32+
- name: Download artifacts
33+
uses: actions/download-artifact@v4
34+
with:
35+
path: artifacts
36+
merge-multiple: true
37+
- name: Upload release artifacts
38+
uses: softprops/action-gh-release@v2
39+
with:
40+
fail_on_unmatched_files: true
41+
files: ./artifacts/*
1642
nginx-build-test:
1743
name: nginx
1844
runs-on: ubuntu-24.04
@@ -55,6 +81,7 @@ jobs:
5581
cd instrumentation/nginx
5682
docker build -t otel-nginx-test/nginx \
5783
--build-arg image=${{ matrix.image }} \
84+
--build-arg nginx_version=${{ matrix.nginx }} \
5885
-f test/${{ env.dockerfile }} \
5986
--cache-from type=local,src=/tmp/buildx-cache/nginx \
6087
--cache-to type=local,dest=/tmp/buildx-cache/nginx-new \
@@ -80,11 +107,15 @@ jobs:
80107
mkdir -p /tmp/otel_ngx/
81108
docker build -f test/${{ env.dockerfile }} \
82109
--build-arg image=${{ matrix.image }} \
110+
--build-arg nginx_version=${{ matrix.nginx }} \
83111
--target export \
84112
--output type=local,dest=/tmp/otel_ngx .
85113
echo "artifactName=otel_ngx_module-$(echo ${{ matrix.image }} | sed s/:/-/)-${{ matrix.nginx }}.so" >> $GITHUB_ENV
114+
- name: rename artifact
115+
run: |
116+
mv /tmp/otel_ngx/otel_ngx_module.so /tmp/otel_ngx/${{ env.artifactName }}
86117
- name: upload artifacts
87118
uses: actions/upload-artifact@v4
88119
with:
89120
name: ${{ env.artifactName }}
90-
path: /tmp/otel_ngx/otel_ngx_module.so
121+
path: /tmp/otel_ngx/${{ env.artifactName }}

exporters/fluentd/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ endif()
5656

5757
include_directories(include)
5858

59+
if(OPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL)
60+
add_definitions(-DOPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL)
61+
endif()
62+
5963
# create fluentd trace exporter
6064
add_library(opentelemetry_exporter_geneva_trace src/trace/fluentd_exporter.cc
6165
src/trace/recordable.cc)
@@ -72,7 +76,7 @@ else()
7276
target_link_libraries(
7377
opentelemetry_exporter_geneva_trace
7478
PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_common
75-
INTERFACE nlohmann_json::nlohmann_json)
79+
nlohmann_json::nlohmann_json)
7680
endif()
7781

7882
# create fluentd logs exporter
@@ -93,7 +97,7 @@ else()
9397
target_link_libraries(
9498
opentelemetry_exporter_geneva_logs
9599
PUBLIC opentelemetry_logs opentelemetry_resources opentelemetry_common
96-
INTERFACE nlohmann_json::nlohmann_json)
100+
nlohmann_json::nlohmann_json)
97101
endif()
98102

99103
if(nlohmann_json_clone)

exporters/fluentd/include/opentelemetry/exporters/fluentd/common/fluentd_common.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include "opentelemetry/common/attribute_value.h"
7+
#include "opentelemetry/sdk/common/attribute_utils.h"
78
#include "opentelemetry/exporters/fluentd/common/fluentd_logging.h"
89
#include "opentelemetry/nostd/string_view.h"
910
#include "opentelemetry/version.h"
@@ -99,6 +100,93 @@ void inline PopulateAttribute(
99100
}
100101
}
101102

103+
void inline PopulateOwnedAttribute(
104+
nlohmann::json &attribute, nostd::string_view key,
105+
const opentelemetry::sdk::common::OwnedAttributeValue &value) {
106+
// Assert size of variant to ensure that this method gets updated if the
107+
// variant definition changes
108+
static_assert(
109+
nostd::variant_size<opentelemetry::common::AttributeValue>::value ==
110+
kAttributeValueSize + 1,
111+
"AttributeValue contains unknown type");
112+
113+
namespace common = opentelemetry::sdk::common;
114+
switch(value.index()) {
115+
case common::kTypeBool:
116+
attribute[key.data()] = nostd::get<bool>(value);
117+
break;
118+
case common::kTypeInt:
119+
attribute[key.data()] = nostd::get<int>(value);
120+
break;
121+
case common::kTypeUInt:
122+
attribute[key.data()] = nostd::get<unsigned int>(value);
123+
break;
124+
case common::kTypeInt64:
125+
attribute[key.data()] = nostd::get<int64_t>(value);
126+
break;
127+
case common::kTypeDouble:
128+
attribute[key.data()] = nostd::get<double>(value);
129+
break;
130+
case common::kTypeString:
131+
attribute[key.data()] = nostd::get<std::string>(value);
132+
break;
133+
case common::kTypeSpanBool:
134+
attribute[key.data()] = {};
135+
for (const auto &val : nostd::get<std::vector<bool>>(value)) {
136+
attribute[key.data()].push_back(val);
137+
}
138+
break;
139+
case common::kTypeSpanInt:
140+
attribute[key.data()] = {};
141+
for (const auto &val : nostd::get<std::vector<int>>(value)) {
142+
attribute[key.data()].push_back(val);
143+
}
144+
break;
145+
case common::kTypeSpanUInt:
146+
attribute[key.data()] = {};
147+
for (const auto &val : nostd::get<std::vector<unsigned int>>(value)) {
148+
attribute[key.data()].push_back(val);
149+
}
150+
break;
151+
case common::kTypeSpanInt64:
152+
attribute[key.data()] = {};
153+
for (const auto &val : nostd::get<std::vector<int64_t>>(value)) {
154+
attribute[key.data()].push_back(val);
155+
}
156+
break;
157+
case common::kTypeSpanDouble:
158+
attribute[key.data()] = {};
159+
for (const auto &val : nostd::get<std::vector<double>>(value)) {
160+
attribute[key.data()].push_back(val);
161+
}
162+
break;
163+
case common::kTypeSpanString:
164+
attribute[key.data()] = {};
165+
for (const auto &val :
166+
nostd::get<std::vector<std::string>>(value)) {
167+
attribute[key.data()].push_back(val);
168+
}
169+
break;
170+
case common::kTypeUInt64:
171+
attribute[key.data()] = nostd::get<uint64_t>(value);
172+
break;
173+
case common::kTypeSpanUInt64:
174+
attribute[key.data()] = {};
175+
for (const auto &val : nostd::get<std::vector<uint64_t>>(value)) {
176+
attribute[key.data()].push_back(val);
177+
}
178+
break;
179+
case common::kTypeSpanByte:
180+
attribute[key.data()] = {};
181+
for (const auto &val : nostd::get<std::vector<uint8_t>>(value)) {
182+
attribute[key.data()].push_back(val);
183+
}
184+
break;
185+
default:
186+
break;
187+
}
188+
}
189+
102190
inline std::string AttributeValueToString(
103191
const opentelemetry::common::AttributeValue &value) {
104192
std::string result;

exporters/fluentd/include/opentelemetry/exporters/fluentd/log/recordable.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ class Recordable final : public opentelemetry::sdk::logs::Recordable {
4444
* @param Resource the resource to set
4545
*/
4646
void SetResource(const opentelemetry::sdk::resource::Resource
47+
#ifdef OPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL
48+
&resource) noexcept override;
49+
#else
4750
&resource) noexcept override {} // Not Supported
48-
51+
#endif
4952
/**
5053
* Set an attribute of a log.
5154
* @param key the key of the attribute

exporters/fluentd/src/log/recordable.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "opentelemetry/exporters/fluentd/common/fluentd_common.h"
66
#include "opentelemetry/exporters/fluentd/common/fluentd_logging.h"
77

8+
#include "opentelemetry/sdk/resource/resource.h"
89
#include "opentelemetry/logs/severity.h"
910
#include "opentelemetry/trace/span_id.h"
1011
#include "opentelemetry/trace/trace_id.h"
@@ -54,6 +55,20 @@ void Recordable::SetSpanId(const opentelemetry::trace::SpanId &span_id) noexcept
5455
json_[FLUENT_FIELD_SPAN_ID] = std::string(span_id_lower_base16, 16);
5556
}
5657

58+
#ifdef OPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL
59+
void Recordable::SetResource(const opentelemetry::sdk::resource::Resource
60+
&resource) noexcept {
61+
if(resource.GetAttributes().size() > 0) {
62+
if (!json_.contains(FLUENT_FIELD_PROPERTIES)) {
63+
json_[FLUENT_FIELD_PROPERTIES] = nlohmann::json::object();
64+
}
65+
}
66+
for(const auto& [key, value] : resource.GetAttributes()) {
67+
fluentd_common::PopulateOwnedAttribute(json_[FLUENT_FIELD_PROPERTIES], key, value);
68+
}
69+
}
70+
#endif
71+
5772
void Recordable::SetAttribute(
5873
nostd::string_view key,
5974
const opentelemetry::common::AttributeValue &value) noexcept {

0 commit comments

Comments
 (0)