Skip to content
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

fix: [#4466] Fix telemetry activityId and conversationId properties #4471

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libraries/botbuilder-core/src/telemetryConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ export class TelemetryConstants {
* The telemetry property value for activity type.
*/
static readonly activityTypeProperty: string = 'type';

/**
* The telemetry property value for activity id.
*/
static readonly activityIdProperty: string = 'activityId';
}
4 changes: 4 additions & 0 deletions libraries/botbuilder-core/src/telemetryLoggerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class TelemetryLoggerMiddleware implements Middleware {
properties[TelemetryConstants.recipientIdProperty] = activity.recipient?.id ?? '';
properties[TelemetryConstants.recipientNameProperty] = activity.recipient?.name ?? '';
properties[TelemetryConstants.activityTypeProperty] = activity.type ?? '';
properties[TelemetryConstants.activityIdProperty] = activity.id ?? '';

// Use the LogPersonalInformation flag to toggle logging PII data, text and user name are common examples
if (this.logPersonalInformation) {
Expand Down Expand Up @@ -283,6 +284,7 @@ export class TelemetryLoggerMiddleware implements Middleware {
properties[TelemetryConstants.conversationNameProperty] = activity.conversation?.name ?? '';
properties[TelemetryConstants.localeProperty] = activity.locale ?? '';
properties[TelemetryConstants.activityTypeProperty] = activity.type ?? '';
properties[TelemetryConstants.activityIdProperty] = activity.id ?? '';

// Use the LogPersonalInformation flag to toggle logging PII data, text and user name are common examples
if (this.logPersonalInformation) {
Expand Down Expand Up @@ -337,6 +339,7 @@ export class TelemetryLoggerMiddleware implements Middleware {
properties[TelemetryConstants.conversationNameProperty] = activity.conversation?.name ?? '';
properties[TelemetryConstants.localeProperty] = activity.locale ?? '';
properties[TelemetryConstants.activityTypeProperty] = activity.type ?? '';
properties[TelemetryConstants.activityIdProperty] = activity.id ?? '';

// Use the LogPersonalInformation flag to toggle logging PII data, text is a common example
if (this.logPersonalInformation) {
Expand Down Expand Up @@ -375,6 +378,7 @@ export class TelemetryLoggerMiddleware implements Middleware {
properties[TelemetryConstants.conversationIdProperty] = activity.conversation?.id ?? '';
properties[TelemetryConstants.conversationNameProperty] = activity.conversation?.name ?? '';
properties[TelemetryConstants.activityTypeProperty] = activity.type ?? '';
properties[TelemetryConstants.activityIdProperty] = activity.id ?? '';

// Additional Properties can override "stock" properties.
if (telemetryProperties) {
Expand Down
5 changes: 5 additions & 0 deletions libraries/botbuilder-core/src/turnContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ export class TurnContext {
} else {
const responses = await this.adapter.sendActivities(this, output);

for (let index = 0; index < responses?.length; index++) {
const activity = output[index];
activity.id = responses[index].id;
}

// Set responded flag
if (sentNonTraceActivity) {
this.responded = true;
Expand Down
2 changes: 2 additions & 0 deletions libraries/botbuilder-core/tests/telemetryMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ describe('TelemetryMiddleware', function () {

const expectTrackEvent = (name, properties = {}) => {
expectExactEvent(name, {
conversationId: sinon.match.string,
conversationName: sinon.match.string,
recipientId: sinon.match.string,
type: sinon.match.string,
activityId: sinon.match.string,
...properties,
});
};
Expand Down