Skip to content

Commit aaa4b65

Browse files
[OneDS] Integrate Event Tracking Mechanism in OneDS (#1115)
* Add * Integrate Event Tracking Mechanism in 1DS * Fix unnecessary file * Remove file checked in by mistake * Update description for macro * Comment Fix
1 parent ba37c8f commit aaa4b65

16 files changed

+42
-0
lines changed

docs/building-custom-SKU.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Build recipe must contain the following preprocessor definitions:
2626
| HAVE_MAT_ZLIB | on | Use zlib for HTTP requests compression. This option must always be turned on for any high-volume telemetry project |
2727
| HAVE_MAT_LOGGING | on | Enable internal SDK tracing / debug logging |
2828
| HAVE_MAT_WIN_LOG | off | Will log statements to disk on windows if trace enabled and HAVE_MAT_LOGGING defined |
29+
| HAVE_MAT_EVT_TRACEID | off | Enable event tracking by adding trace-id to http request header on Windows. This is for debugging purpose, and not recommended to be enabled in production. The collector doesn't parse/read this header. As of now, this is meant to be used through the capi, where the http-send handler should remove this header from the event data before sending it to collector. |
2930
| HAVE_MAT_STORAGE | on | Enable SQLite persistent offline storage |
3031
| HAVE_MAT_NETDETECT | on | _Win32 Desktop only_: Use NLM COM object for network cost detection on Windows 8+ |
3132
| HAVE_MAT_SHORT_NS | off | Use short "MAT::" namespace instead of "Microsoft::Applications::Events::" to reduce the .DLL size |

lib/http/HttpRequestEncoder.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ namespace MAT_NS_BEGIN {
4545
ctx->httpRequest->SetUrl(m_config.GetCollectorUrl());
4646

4747
ctx->httpRequest->GetHeaders().set("Expect", "100-continue");
48+
49+
#ifdef HAVE_MAT_EVT_TRACEID
50+
ctx->httpRequest->GetHeaders().set("Trace-Id", ctx->traceId);
51+
#endif //HAVE_MAT_EVT_TRACEID
52+
4853
ctx->httpRequest->GetHeaders().set("SDK-Version", PAL::getSdkVersion());
4954
ctx->httpRequest->GetHeaders().set("Client-Id", "NO_AUTH");
5055
ctx->httpRequest->GetHeaders().set("Content-Type", "application/bond-compact-binary");

lib/include/mat/config-MIP.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define HAVE_MAT_ZLIB
1414
#define HAVE_MAT_LOGGING
1515
#define HAVE_MAT_WIN_LOG
16+
#define HAVE_MAT_EVT_TRACEID
1617
#define HAVE_MAT_STORAGE
1718
#if defined(_WIN32)
1819
#define WIN_DESKTOP

lib/include/mat/config-MSIPC.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define HAVE_MAT_ZLIB
1717
#define HAVE_MAT_LOGGING
1818
/* #define HAVE_MAT_WIN_LOG */
19+
/* #define HAVE_MAT_EVT_TRACEID */
1920
#define HAVE_MAT_STORAGE
2021
#define WIN_DESKTOP
2122
#define HAVE_MAT_DEFAULT_HTTP_CLIENT

lib/include/mat/config-compact-dll.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define HAVE_MAT_ZLIB
1515
/* #define HAVE_MAT_LOGGING */
1616
/* #define HAVE_MAT_WIN_LOG */
17+
/* #define HAVE_MAT_EVT_TRACEID */
1718
/* #define HAVE_MAT_STORAGE */
1819
/* #define HAVE_MAT_NETDETECT */
1920
/* #define HAVE_MAT_SHORT_NS */

lib/include/mat/config-compact-exp.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define HAVE_MAT_ZLIB
1515
/* #define HAVE_MAT_LOGGING */
1616
/* #define HAVE_MAT_WIN_LOG */
17+
/* #define HAVE_MAT_EVT_TRACEID */
1718
#define HAVE_MAT_STORAGE
1819
/* #define HAVE_MAT_NETDETECT */
1920
/* #define HAVE_MAT_SHORT_NS */

lib/include/mat/config-compact-min.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/* #define HAVE_MAT_ZLIB */
1515
/* #define HAVE_MAT_LOGGING */
1616
/* #define HAVE_MAT_WIN_LOG */
17+
/* #define HAVE_MAT_EVT_TRACEID */
1718
/* #define HAVE_MAT_STORAGE */
1819
/* #define HAVE_MAT_NETDETECT */
1920
/* #define HAVE_MAT_SHORT_NS */

lib/include/mat/config-compact-noutc.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/* #define HAVE_MAT_ZLIB */
1515
/* #define HAVE_MAT_LOGGING */
1616
/* #define HAVE_MAT_WIN_LOG */
17+
/* #define HAVE_MAT_EVT_TRACEID */
1718
/* #define HAVE_MAT_STORAGE */
1819
/* #define HAVE_MAT_NETDETECT */
1920
#define HAVE_MAT_SHORT_NS

lib/include/mat/config-compact.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/* #define HAVE_MAT_ZLIB */
1515
/* #define HAVE_MAT_LOGGING */
1616
/* #define HAVE_MAT_WIN_LOG */
17+
/* #define HAVE_MAT_EVT_TRACEID */
1718
/* #define HAVE_MAT_STORAGE */
1819
/* #define HAVE_MAT_NETDETECT */
1920
#define HAVE_MAT_SHORT_NS

lib/include/mat/config-default-cs4.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define HAVE_MAT_ZLIB
2525
#define HAVE_MAT_LOGGING
2626
/* #define HAVE_MAT_WIN_LOG */
27+
/* #define HAVE_MAT_EVT_TRACEID */
2728
#define HAVE_MAT_STORAGE
2829
#define HAVE_MAT_DEFAULT_HTTP_CLIENT
2930
#define HAVE_MAT_LIVEEVENTINSPECTOR

lib/include/mat/config-default-exp.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define HAVE_MAT_ZLIB
2323
#define HAVE_MAT_LOGGING
2424
/* #define HAVE_MAT_WIN_LOG */
25+
/* #define HAVE_MAT_EVT_TRACEID */
2526
#define HAVE_MAT_STORAGE
2627
#define HAVE_MAT_DEFAULT_HTTP_CLIENT
2728
#define HAVE_MAT_LIVEEVENTINSPECTOR

lib/include/mat/config-default.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define HAVE_MAT_ZLIB
2525
#define HAVE_MAT_LOGGING
2626
/* #define HAVE_MAT_WIN_LOG */
27+
/* #define HAVE_MAT_EVT_TRACEID */
2728
#define HAVE_MAT_STORAGE
2829
#define HAVE_MAT_DEFAULT_HTTP_CLIENT
2930
#define HAVE_MAT_LIVEEVENTINSPECTOR

lib/include/mat/config-net40.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define HAVE_MAT_ZLIB
1717
#define HAVE_MAT_LOGGING
1818
/* #define HAVE_MAT_WIN_LOG */
19+
/* #define HAVE_MAT_EVT_TRACEID */
1920
#define HAVE_MAT_STORAGE
2021
/*
2122
#if defined(_WIN32) && !defined(_WINRT_DLL)

lib/include/public/IOfflineStorage.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@ namespace MAT_NS_BEGIN {
3333
StorageBlob blob;
3434
int retryCount = 0;
3535
int64_t reservedUntil = 0;
36+
#ifdef HAVE_MAT_EVT_TRACEID
37+
std::string traceId;
38+
#endif // HAVE_MAT_EVT_TRACEID
3639

3740
StorageRecord()
3841
{}
3942

43+
#ifdef HAVE_MAT_EVT_TRACEID
44+
StorageRecord(std::string const& id, std::string const& tenantToken, EventLatency latency, EventPersistence persistence, std::string traceId)
45+
: id(id), tenantToken(tenantToken), latency(latency), persistence(persistence), traceId(traceId)
46+
{}
47+
#else
4048
StorageRecord(std::string const& id, std::string const& tenantToken, EventLatency latency, EventPersistence persistence)
4149
: id(id), tenantToken(tenantToken), latency(latency), persistence(persistence)
4250
{}
51+
#endif // HAVE_MAT_EVT_TRACEID
4352

4453
StorageRecord(std::string const& id, std::string const& tenantToken, EventLatency latency, EventPersistence persistence,
4554
int64_t timestamp, std::vector<uint8_t>&& blob, int retryCount = 0, int64_t reservedUntil = 0)

lib/packager/Packager.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ namespace MAT_NS_BEGIN {
4848
LOG_TRACE("Adding event %s:%s, size %u bytes",
4949
tenantTokenToId(record.tenantToken).c_str(), record.id.c_str(), static_cast<unsigned>(record.blob.size()));
5050

51+
#ifdef HAVE_MAT_EVT_TRACEID
52+
ctx->traceId = record.traceId;
53+
#endif // HAVE_MAT_EVT_TRACEID
54+
5155
std::string const& tenantToken = m_forcedTenantToken.empty() ? record.tenantToken : m_forcedTenantToken;
5256
auto it = ctx->packageIds.lower_bound(tenantToken);
5357
if (it == ctx->packageIds.end() || it->first != tenantToken)

lib/system/Contexts.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ namespace MAT_NS_BEGIN {
3232
{
3333
}
3434

35+
#ifdef HAVE_MAT_EVT_TRACEID
36+
IncomingEventContext(std::string const& id, std::string const& tenantToken, EventLatency latency, EventPersistence persistence, ::CsProtocol::Record* source)
37+
: source(source),
38+
record{ id, tenantToken, latency, persistence, (source != nullptr) ? source->cV : "" },
39+
policyBitFlags(0)
40+
{
41+
}
42+
#else
3543
IncomingEventContext(std::string const& id, std::string const& tenantToken, EventLatency latency, EventPersistence persistence, ::CsProtocol::Record* source)
3644
: source(source),
3745
record{ id, tenantToken, latency, persistence },
3846
policyBitFlags(0)
3947
{
4048
}
49+
#endif
4150

4251
virtual ~IncomingEventContext()
4352
{
@@ -88,6 +97,9 @@ namespace MAT_NS_BEGIN {
8897
unsigned maxUploadSize = 0;
8998
EventLatency latency = EventLatency_Unspecified;
9099
std::map<std::string, size_t> packageIds;
100+
#ifdef HAVE_MAT_EVT_TRACEID
101+
std::string traceId;
102+
#endif
91103
std::map<std::string, std::string> recordIdsAndTenantIds;
92104
std::vector<int64_t> recordTimestamps;
93105
unsigned maxRetryCountSeen = 0;

0 commit comments

Comments
 (0)