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

Hackathon - log drain #1373

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft

Hackathon - log drain #1373

wants to merge 36 commits into from

Conversation

lkostrowski
Copy link
Member

Scope of the PR

Related issues

Checklist

Copy link

vercel bot commented May 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
saleor-app-avatax ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2024 9:21am
saleor-app-smtp ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2024 9:21am
9 Ignored Deployments
Name Status Preview Comments Updated (UTC)
saleor-app-cms ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-crm ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-data-importer ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-emails-and-messages ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-invoices ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-klaviyo ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-products-feed ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-search ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am
saleor-app-segment ⬜️ Ignored (Inspect) Visit Preview May 29, 2024 9:21am

Copy link

changeset-bot bot commented May 28, 2024

⚠️ No Changeset found

Latest commit: 315d27d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member Author

@lkostrowski lkostrowski left a comment

Choose a reason for hiding this comment

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

few comments to make it "mergable"

json: z.object({
enabled: z.boolean().optional(),
url: z.string().optional(),
headers: z.string().optional(),
Copy link
Member Author

Choose a reason for hiding this comment

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

here we should add json validation, so it doesnt shoot anyone in the foot. it will be hard to notice missing " and it will fallback to {} causing auth errors. so we need custom validation, as simple as json.parse() in try/catch

@@ -141,6 +141,8 @@ export const EditAvataxConfiguration = () => {
);
}

console.log("config", data.config);
Copy link
Member Author

Choose a reason for hiding this comment

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

to remove

import { AvataxConfig } from "../avatax-connection-schema";
import { HelperText } from "./form-helper-text";

export const LogsSettingsFragment = () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

we should have it in shared packages IMO but I think first we can finish this PR, then plan to enable it in other apps → we will extract form into shared package

UI can be shared easily, but we need to make form decoupled from data source

name="logsSettings.otel.enabled"
control={control}
label="OTEL transport"
helperText={<HelperText>Enable sending logs using OpenTelemetry protocol.</HelperText>}
Copy link
Member Author

Choose a reason for hiding this comment

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

we need to also:

  1. write that this is JSON HTTP standard (not be confused with proto)
  2. add some links to docs of open telemetry etc

@@ -127,6 +139,11 @@ describe("CalculateTaxesUseCase", () => {

instance = new CalculateTaxesUseCase({
configExtractor: MockConfigExtractor,
publicLogDrain: new PublicLogDrainService([
{
async emit(log: PublicLog): Promise<void> {},
Copy link
Member Author

Choose a reason for hiding this comment

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

we should add test that checks if log drain emits when use case runs

Comment on lines +248 to +254
const sourceObjectType = payload.taxBase.sourceObject.__typename;
const sourceObjectId = payload.taxBase.sourceObject.id;
const orderOrCheckoutId =
payload.taxBase.sourceObject.__typename === "Checkout"
? { checkoutId: sourceObjectId }
: { orderId: sourceObjectId };
const saleorApiUrl = authData.saleorApiUrl;
Copy link
Member Author

Choose a reason for hiding this comment

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

we can wrap in private method of clarity

};

class TaxesCalculationFailedLog implements PublicLog<CheckoutOrOrderId> {
message = "Taxes calculation failed";
Copy link
Member Author

Choose a reason for hiding this comment

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

if we have separate events for successful calculations for checkout and order, we should probably be consistent here too

Comment on lines +27 to +34
const payload = {
...log,
traceId: spanContext?.traceId,
spanId: spanContext?.spanId,
isRemote: spanContext?.isRemote,
traceFlags: spanContext?.traceFlags,
traceState: spanContext?.traceState?.serialize(),
};
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe otel provides type for this?

return value;
}

private _filterAndTruncateAttributes(attributes: Record<string, unknown>) {
Copy link
Member Author

Choose a reason for hiding this comment

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

we dont have to use _ . We use typescript and have private methods

Comment on lines +154 to +160
try {
headers = JSON.parse(
providerConfig.value.avataxConfig.config.logsSettings.otel.headers ?? "",
);
} catch {
headers = {};
}
Copy link
Member Author

Choose a reason for hiding this comment

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

we should likely use dedicated class that wraps config and exposes parsed config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App: AvaTax skip changeset Attach this label to PRs which does not need changes description for the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants