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(api): add stats to inbound lambda #2068

Merged
merged 13 commits into from
May 23, 2024
Merged

fix(api): add stats to inbound lambda #2068

merged 13 commits into from
May 23, 2024

Conversation

Orta21
Copy link
Member

@Orta21 Orta21 commented May 10, 2024

Ref. metriport/metriport-internal#1669

Ticket: #1889

Dependencies

Description

Add analytics to inbound to determine how often we respond with docs after Patient Match

Testing

  • Staging
    • Infra works accordingly
    • Able to see analytics for inbound requests
  • Production
    • Infra works accordingly
    • Able to see analytics for inbound requests

Release Plan

  • Upstream PR is merged
  • Release NPM packages
  • Merge this

@@ -70,7 +70,7 @@ export async function calculateDocumentConversionStatus({
});

if (isConversionCompleted) {
const startedAt = updatedPatient.data.documentQueryProgress?.startedAt;
const startedAt = externalData?.documentQueryProgress?.startedAt;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot about this but its affected by scheduling the DQ so need to get the HIE startAt

@@ -17,7 +17,9 @@ export type InboundDocumentQueryRespSuccessful = z.infer<
typeof inboundDocumentQueryRespSuccessfulSchema
>;

const inboundDocumentQueryRespFaultSchema = baseErrorResponseSchema;
const inboundDocumentQueryRespFaultSchema = baseErrorResponseSchema.extend({
extrinsicObjectXmls: z.never().or(z.literal(undefined)),
Copy link
Member Author

@Orta21 Orta21 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i dont set as never when erroringi cant extract from result when successful

const inboundDocumentRetrievalRespFaultSchema = baseErrorResponseSchema;
const inboundDocumentRetrievalRespFaultSchema = baseErrorResponseSchema.extend({
documentReference: z.never().or(z.literal(undefined)),
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

static getPostHogApiKey(): string | undefined {
return getEnvVar("POST_HOG_API_KEY");
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to core

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it was moved to core, but we need to add code to the lambda to get the value from the env var and call the AWS SDK to get the value of the secret w/ the env var content.

@Orta21 Orta21 marked this pull request as ready for review May 10, 2024 19:04
Copy link
Contributor

@RamilGaripov RamilGaripov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment, which is kind of a nit... Address at your discretion 😄

Also, would be good to release NPM packages after a PR is approved, so:

  1. there are no iterations on NPM releases in case a change is requested in a published package, and
  2. the pkg version updates don't litter the PR

packages/infra/lib/ihe-stack.ts Show resolved Hide resolved
packages/infra/lib/ihe-stack.ts Outdated Show resolved Hide resolved
packages/infra/lib/ihe-stack.ts Outdated Show resolved Hide resolved
packages/infra/lib/ihe-stack.ts Outdated Show resolved Hide resolved
packages/infra/lib/ihe-stack.ts Outdated Show resolved Hide resolved
packages/infra/lib/ihe-stack.ts Outdated Show resolved Hide resolved
packages/infra/lib/ihe-stack.ts Outdated Show resolved Hide resolved
static getPostHogApiKey(): string | undefined {
return getEnvVar("POST_HOG_API_KEY");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it was moved to core, but we need to add code to the lambda to get the value from the env var and call the AWS SDK to get the value of the secret w/ the env var content.

packages/infra/lib/ihe-stack.ts Show resolved Hide resolved
Comment on lines 24 to 26
if (postHogSecretName) {
postHogApiKey = await getSecretValue(postHogSecretName, region);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to call analytics if there's no API key?

Comment on lines 95 to 97
static getUseMockS3Utils(): boolean {
return getEnvVar("USE_MOCK_S3_UTILS") === "true";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not part of this PR, is it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill remove since its not being used anywere but seems like its already part of the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

seems like its already part of the code

FYI, that usually happens after a bad conflict resolution.

const posthog = new PostHog(postApiKey);
export const analytics = (params: EventMessageV1, postApiKey?: string) => {
const apiKey = postApiKey ?? defaultPostHogApiKey;
if (apiKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since we're touching this, could make this return if no api key available, instead of having the main flow inside an if

NABD, though

@Orta21 Orta21 added this pull request to the merge queue May 23, 2024
Merged via the queue into develop with commit 87cb73a May 23, 2024
35 checks passed
@Orta21 Orta21 deleted the 1669-inbound-stats branch May 23, 2024 13:22
@Orta21 Orta21 mentioned this pull request May 23, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants