Skip to content

Commit

Permalink
access analytics consent from OtelKernel
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Dec 4, 2024
1 parent 9e14a13 commit ed56311
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Backend/Otel/OtelKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public static void AddOpenTelemetryInstrumentation(this IServiceCollection servi
);
}

internal static void TrackConsent(Activity activity, HttpRequest request)
{
var consent = request.Headers.TryGetValue("otelConsent", out var values) ? values.FirstOrDefault() : "nothing";
activity.SetBaggage("otelConsent", consent);
}

internal static void TrackSession(Activity activity, HttpRequest request)
{
var sessionId = request.Headers.TryGetValue("sessionId", out var values) ? values.FirstOrDefault() : null;
Expand Down Expand Up @@ -67,6 +73,7 @@ private static void AspNetCoreBuilder(AspNetCoreTraceInstrumentationOptions opti
options.EnrichWithHttpRequest = (activity, request) =>
{
GetContentLengthAspNet(activity, request.Headers, "inbound.http.request.body.size");
TrackConsent(activity, request);
TrackSession(activity, request);
};
options.EnrichWithHttpResponse = (activity, response) =>
Expand Down Expand Up @@ -98,7 +105,8 @@ internal class LocationEnricher(ILocationProvider locationProvider) : BaseProces
{
public override async void OnEnd(Activity data)
{
var uriPath = (string?)data.GetTagItem("url.full");
data?.SetTag("consent value", data?.GetBaggageItem("otelConsent"));
var uriPath = (string?)data?.GetTagItem("url.full");
var locationUri = LocationProvider.locationGetterUri;
if (uriPath is null || !uriPath.Contains(locationUri))
{
Expand Down
3 changes: 3 additions & 0 deletions src/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const whiteListedErrorUrls = [
const axiosInstance = axios.create({ baseURL: apiBaseURL });
axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
config.headers.sessionId = getSessionId();
LocalStorage.getCurrentUser()?.otelConsent
? (config.headers.otelConsent = "yay")
: (config.headers.otelConsent = "nay");
return config;
});
axiosInstance.interceptors.response.use(undefined, (err: AxiosError) => {
Expand Down

0 comments on commit ed56311

Please sign in to comment.