-
Notifications
You must be signed in to change notification settings - Fork 69
(EAI-950) Segment - Send data feed to Segment #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
segmentUserId: res.locals.customData.segmentUserId ?? "NOPE", | ||
segmentAnonymousId: res.locals.customData.segmentAnonymousId ?? "NOPE", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do null
rather than 'NOPE'
? or does 'NOPE' mean something to segment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops did that for testing purposes and used a silly word so that I'd notice it later. Good catch!
if (userMessage) { | ||
segmentTrackUserSentMessage?.({ | ||
userId, | ||
anonymousId, | ||
conversationId: conversation._id, | ||
origin: userMessage.customData?.origin as string, | ||
createdAt: userMessage.createdAt, | ||
tags: tracingData.tags, | ||
}); | ||
} | ||
|
||
const assistantMessage = tracingData.assistantMessage; | ||
if (userMessage && assistantMessage) { | ||
segmentTrackAssistantResponded?.({ | ||
userId, | ||
anonymousId, | ||
conversationId: conversation._id, | ||
origin: userMessage.customData?.origin as string, | ||
createdAt: assistantMessage.createdAt, | ||
isVerifiedAnswer: tracingData.isVerifiedAnswer ?? false, | ||
rejectionReason: tracingData.rejectQuery | ||
? (assistantMessage.customData?.rejectionReason as | ||
| string | ||
| undefined) ?? "Unknown rejection reason" | ||
: undefined, | ||
}); | ||
} | ||
|
||
logger.updateSpan({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that there are 2 separate things happening in this trace func, should we wrap each w/ a try/catch block?
i know both aren't async, since the processing happening in background..but still.
not sure what right approach is, but wanted to raise the question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - added try catch. Also needed a mongodb-chatbot-server
update so that we pass the reqId
for logging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me. see comment on handling the 2 traces with try/catch blocks
res.locals.customData.segmentUserId = userId; | ||
} | ||
if (anonymousId) { | ||
res.locals.customData.segmentAnonymousId = anonymousId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by including this, does it mean that we're now tracking the segment user and anon IDs in the DB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we will track these in user message customData
. I think they classify as PII so don't want to keep them in scrubbed_messages
.
out of curiousity, whaat do the segment ID and anon IDs look like? and where are they coming from? can we connect a segment ID back to a real user, like w/ email or smthn? |
They're UUIDs with slightly different formats, e.g.
They're stored in localStorage on MongoDB web properties that include Segment's AnalyticsJS (pretty much all of our sites, including docs)
I think the |
Jira: (EAI-950) Segment - Send data feed to Segment
Changes
useSegmentIds
middleware to pull out Segment user IDs from request headerssegment
handlers that send chatbot events to SegmentSEGMENT_WRITE_KEY
env var to route requests