diff --git a/app/client/src/UITelemetry/generateTraces.ts b/app/client/src/UITelemetry/generateTraces.ts index 71b417a73217..011a66632c75 100644 --- a/app/client/src/UITelemetry/generateTraces.ts +++ b/app/client/src/UITelemetry/generateTraces.ts @@ -87,6 +87,17 @@ export function setAttributesToSpan( span?.setAttributes(spanAttributes); } +export const startAndEndSpanForFn = ( + spanName: string, + spanAttributes: SpanAttributes = {}, + fn: () => T, +) => { + const span = startRootSpan(spanName, spanAttributes); + const res: T = fn(); + span.end(); + return res; +}; + export function wrapFnWithParentTraceContext(parentSpan: Span, fn: () => any) { const parentContext = trace.setSpan(context.active(), parentSpan); return context.with(parentContext, fn); diff --git a/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts b/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts index 27c100e90ae8..4871e0a37037 100644 --- a/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts +++ b/app/client/src/widgets/JSONFormWidget/fields/useRegisterFieldValidity.ts @@ -7,6 +7,7 @@ import { klona } from "klona"; import FormContext from "../FormContext"; import type { FieldType } from "../constants"; +import { startAndEndSpanForFn } from "UITelemetry/generateTraces"; export interface UseRegisterFieldValidityProps { isValid: boolean; @@ -34,10 +35,14 @@ function useRegisterFieldValidity({ setTimeout(() => { try { isValid - ? clearErrors(fieldName) - : setError(fieldName, { - type: fieldType, - message: "Invalid field", + ? startAndEndSpanForFn("JSONFormWidget.clearErrors", {}, () => { + clearErrors(fieldName); + }) + : startAndEndSpanForFn("JSONFormWidget.setError", {}, () => { + setError(fieldName, { + type: fieldType, + message: "Invalid field", + }); }); } catch (e) { Sentry.captureException(e); diff --git a/app/client/src/widgets/JSONFormWidget/widget/index.tsx b/app/client/src/widgets/JSONFormWidget/widget/index.tsx index 2381507dae72..0d708d98af78 100644 --- a/app/client/src/widgets/JSONFormWidget/widget/index.tsx +++ b/app/client/src/widgets/JSONFormWidget/widget/index.tsx @@ -68,6 +68,7 @@ import { ONSUBMIT_NOT_CONFIGURED_MESSAGE, } from "../constants/messages"; import { createMessage } from "@appsmith/constants/messages"; +import { endSpan, startRootSpan } from "UITelemetry/generateTraces"; const SUBMIT_BUTTON_DEFAULT_STYLES = { buttonVariant: ButtonVariantTypes.PRIMARY, @@ -651,6 +652,7 @@ class JSONFormWidget extends BaseWidget< schema: Schema, afterUpdateAction?: ExecuteTriggerPayload, ) => { + const span = startRootSpan("JSONFormWidget.parseAndSaveFieldState"); const fieldState = generateFieldState(schema, metaInternalFieldState); const action = klona(afterUpdateAction); @@ -664,6 +666,7 @@ class JSONFormWidget extends BaseWidget< actionPayload, ); } + endSpan(span); }; onSubmit = (event: React.MouseEvent) => {