Skip to content

Commit 6a96b13

Browse files
feat: Inline context for custom events (#477)
1 parent f429fdb commit 6a96b13

File tree

10 files changed

+29
-31
lines changed

10 files changed

+29
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This includes shared libraries, used by SDKs and other tools, as well as SDKs.
2020
## Organization
2121

2222
| Directory | Description |
23-
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
23+
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2424
| .github | Contains CI and release process workflows and actions. |
2525
| examples | Contains examples (hello-world style). |
2626
| contract-tests | Contains contract test service. |

contract-tests/client-contract-tests/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
4141
srv.add_capability("service-endpoints");
4242
srv.add_capability("tags");
4343
srv.add_capability("client-independence");
44-
srv.add_capability("inline-context");
44+
srv.add_capability("inline-context-all");
4545
srv.add_capability("anonymous-redaction");
4646
srv.add_capability("tls:verify-peer");
4747
srv.add_capability("tls:skip-verify-peer");

contract-tests/server-contract-tests/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main(int argc, char* argv[]) {
4040
srv.add_capability("service-endpoints");
4141
srv.add_capability("tags");
4242
srv.add_capability("server-side-polling");
43-
srv.add_capability("inline-context");
43+
srv.add_capability("inline-context-all");
4444
srv.add_capability("anonymous-redaction");
4545
srv.add_capability("tls:verify-peer");
4646
srv.add_capability("tls:skip-verify-peer");

libs/client-sdk/src/client_impl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ void ClientImpl::TrackInternal(std::string event_name,
221221
std::optional<Value> data,
222222
std::optional<double> metric_value) {
223223
event_processor_->SendAsync(events::TrackEventParams{
224-
std::chrono::system_clock::now(), std::move(event_name),
225-
ReadContextSynchronized(
226-
[](Context const& c) { return c.KindsToKeys(); }),
224+
std::chrono::system_clock::now(), std::move(event_name), context_,
227225
std::move(data), metric_value});
228226
}
229227

libs/internal/include/launchdarkly/events/data/common_events.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,19 @@ struct Date {
2727
struct TrackEventParams {
2828
Date creation_date;
2929
std::string key;
30-
ContextKeys context_keys;
30+
Context context;
3131
std::optional<Value> data;
3232
std::optional<double> metric_value;
3333
};
3434

35-
struct ServerTrackEventParams {
36-
TrackEventParams base;
37-
Context context;
35+
struct TrackEvent {
36+
Date creation_date;
37+
std::string key;
38+
EventContext context;
39+
std::optional<Value> data;
40+
std::optional<double> metric_value;
3841
};
3942

40-
using ClientTrackEventParams = TrackEventParams;
41-
42-
using TrackEvent = TrackEventParams;
43-
4443
struct IdentifyEventParams {
4544
Date creation_date;
4645
Context context;

libs/internal/include/launchdarkly/events/data/events.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#include <launchdarkly/events/data/server_events.hpp>
55

66
#include <variant>
7+
#include "common_events.hpp"
78

89
namespace launchdarkly::events {
910

10-
using InputEvent = std::variant<FeatureEventParams,
11-
IdentifyEventParams,
12-
ClientTrackEventParams,
13-
ServerTrackEventParams>;
11+
using InputEvent =
12+
std::variant<FeatureEventParams, IdentifyEventParams, TrackEventParams>;
1413

1514
using OutputEvent = std::variant<FeatureEvent,
1615
DebugEvent,

libs/internal/src/events/asio_event_processor.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,24 @@ std::vector<OutputEvent> AsioEventProcessor<SDK>::Process(
273273
out.emplace_back(IdentifyEvent{event.creation_date,
274274
filter_.Filter(event.context)});
275275
},
276-
[&](ClientTrackEventParams&& event) {
277-
out.emplace_back(std::move(event));
278-
},
279-
[&](ServerTrackEventParams&& event) {
276+
[&](TrackEventParams&& event) {
280277
if constexpr (std::is_same<SDK,
281278
config::shared::ServerSDK>::value) {
282279
if (!context_key_cache_.Notice(
283280
event.context.CanonicalKey())) {
284281
out.emplace_back(server_side::IndexEvent{
285-
event.base.creation_date,
282+
event.creation_date,
286283
filter_.Filter(event.context)});
287284
}
288285
}
289286

290-
out.emplace_back(std::move(event.base));
287+
out.emplace_back(TrackEvent{
288+
event.creation_date,
289+
event.key,
290+
filter_.Filter(event.context),
291+
event.data,
292+
event.metric_value,
293+
});
291294
}},
292295
std::move(input_event));
293296

libs/internal/src/serialization/events/json_events.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
#include <launchdarkly/detail/serialization/json_value.hpp>
12
#include <launchdarkly/serialization/events/json_events.hpp>
23
#include <launchdarkly/serialization/json_evaluation_reason.hpp>
3-
#include <launchdarkly/detail/serialization/json_value.hpp>
44

55
namespace launchdarkly::events {
66
void tag_invoke(boost::json::value_from_tag const& tag,
@@ -83,7 +83,7 @@ void tag_invoke(boost::json::value_from_tag const& tag,
8383
obj.emplace("kind", "custom");
8484
obj.emplace("creationDate", boost::json::value_from(event.creation_date));
8585
obj.emplace("key", event.key);
86-
obj.emplace("contextKeys", boost::json::value_from(event.context_keys));
86+
obj.emplace("context", event.context);
8787
if (event.data) {
8888
obj.emplace("data", boost::json::value_from(*event.data));
8989
}

libs/server-sdk/src/events/event_factory.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ events::InputEvent EventFactory::Custom(
4343
std::string event_name,
4444
std::optional<Value> data,
4545
std::optional<double> metric_value) const {
46-
return events::ServerTrackEventParams{
47-
{now_(), std::move(event_name), ctx.KindsToKeys(), std::move(data),
48-
metric_value},
49-
ctx};
46+
return events::TrackEventParams{now_(), std::move(event_name),
47+
std::move(ctx), std::move(data),
48+
metric_value};
5049
}
5150

5251
events::InputEvent EventFactory::FeatureRequest(

libs/server-sdk/tests/event_scope_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ TEST(EventScope, ForwardsCorrectEventTypes) {
6969
ASSERT_TRUE(processor.Kind<events::IdentifyEventParams>(0));
7070
ASSERT_TRUE(processor.Kind<events::FeatureEventParams>(1));
7171
ASSERT_TRUE(processor.Kind<events::FeatureEventParams>(2));
72-
ASSERT_TRUE(processor.Kind<events::ServerTrackEventParams>(3));
72+
ASSERT_TRUE(processor.Kind<events::TrackEventParams>(3));
7373
}

0 commit comments

Comments
 (0)