(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4070],{4970:function(s,e,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/docs/plugins/tracing",function(){return n(7587)}])},7587:function(s,e,n){"use strict";n.r(e),n.d(e,{__N_SSG:function(){return c},frontmatter:function(){return i}});var a=n(5250),l=n(7160),r=n(3210),c=!0;let i={name:"Tracing plugin",title:"Tracing plugin for Pothos GraphQL",menu:"Plugins",description:"A Pothos plugin for tracing and logging resolver invocations"},t=r.k;function h(s){let e=Object.assign({h1:"h1",p:"p",h2:"h2",h3:"h3",pre:"pre",code:"code",span:"span",ol:"ol",li:"li",h4:"h4",ul:"ul"},(0,l.ah)(),s.components);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(e.h1,{id:"tracing-plugin",children:"Tracing Plugin"}),"\n",(0,a.jsx)(e.p,{children:"This plugin adds hooks for tracing and logging resolver invocations. It also comes with a few\nadditional packages for integrating with various tracing providers including opentelemetry, New\nRelic and Sentry."}),"\n",(0,a.jsx)(e.h2,{id:"usage",children:"Usage"}),"\n",(0,a.jsx)(e.h3,{id:"install",children:"Install"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"hljs language-bash",children:"yarn add @pothos/plugin-tracing\n"})}),"\n",(0,a.jsx)(e.h3,{id:"setup",children:"Setup"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-typescript",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { wrapResolver, isRootField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Enable tracing for rootFields by default, other fields need to opt in"}),"\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config),\n    ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Log resolver execution duration"}),"\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options, config"}),") =>"]}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"wrapResolver"}),"(resolver, ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"error, duration"}),") =>"]})," {\n        ",(0,a.jsx)(e.span,{className:"hljs-variable language_",children:"console"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"log"}),"(",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`Executed resolver ",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${config.parentType}"}),".",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${config.name}"})," in ",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${duration}"}),"ms`"]}),");\n      }),\n  },\n});\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"overview",children:"Overview"}),"\n",(0,a.jsx)(e.p,{children:"The Tracing plugin is designed to have very limited overhead, and uses a modular approach to cover a\nwide variety of use cases."}),"\n",(0,a.jsx)(e.p,{children:"The tracing plugin comes with a number of utility functions for implementing common patterns, and a\ncouple of provider specific modules that can be installed separately (described in more detail\nbelow)."}),"\n",(0,a.jsx)(e.p,{children:"The primary interface to the tracing plugin consists of 3 parts:"}),"\n",(0,a.jsxs)(e.ol,{children:["\n",(0,a.jsxs)(e.li,{children:["A new ",(0,a.jsx)(e.code,{children:"tracing"})," option is added to each field, for enabling or configuring tracing for that field"]}),"\n",(0,a.jsxs)(e.li,{children:["The ",(0,a.jsx)(e.code,{children:"tracing.default"})," which is used as a fallback for any field that does not explicitly set its\n",(0,a.jsx)(e.code,{children:"tracing"})," options."]}),"\n",(0,a.jsxs)(e.li,{children:["The ",(0,a.jsx)(e.code,{children:"tracing.wrap"})," function, which takes a resolver, the tracing option for a field, and a field\nconfiguration object, and should return a wrapped/traced version of the resolver."]}),"\n"]}),"\n",(0,a.jsx)(e.h3,{id:"enabling-tracing-for-a-field",children:"Enabling tracing for a field"}),"\n",(0,a.jsxs)(e.p,{children:["Enabling tracing on a field is as simple as setting the tracing option to ",(0,a.jsx)(e.code,{children:"true"})]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:["builder.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"queryType"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"t"}),") =>"]})," ({\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"hello"}),": t.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"({\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"args"}),": { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"name"}),": t.",(0,a.jsx)(e.span,{className:"hljs-property",children:"arg"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"() },\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// enable tracing"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"resolve"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"parent, { name }"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`hello, ",(0,a.jsxs)(e.span,{className:"hljs-subst",children:["${name || ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'World'"}),"}"]}),"`"]}),",\n    }),\n  }),\n});\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"custom-tracing-options",children:"Custom tracing options"}),"\n",(0,a.jsxs)(e.p,{children:["For more advanced tracing setups, you may want to allow fields to provide additional tracing\noptions. You can do this by customizing the ",(0,a.jsx)(e.code,{children:"Tracing"})," generic in the builder."]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { wrapResolver, isRootField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// the `tracing` option can now be a boolean, or an object with a formatMessage function"}),"\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"boolean"})," | { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"formatMessage"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsxs)(e.span,{className:"hljs-params",children:["duration: ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"number"})]}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"string"})," };\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Using custom options in your tracer will be described below"}),"\n    ...\n  },\n});\n\nbuilder.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"queryType"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"t"}),") =>"]})," ({\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"hello"}),": t.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"({\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"args"}),": { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"name"}),": t.",(0,a.jsx)(e.span,{className:"hljs-property",children:"arg"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"() },\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// We can now use custom options when configuring tracing"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"formatMessage"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"duration"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`It took ",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${duration}"}),"ms to say hello`"]})," },\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"resolve"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"parent, { name }"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`hello, ",(0,a.jsxs)(e.span,{className:"hljs-subst",children:["${name || ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'World'"}),"}"]}),"`"]}),",\n    }),\n  }),\n});\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"enabling-tracing-by-default",children:"Enabling tracing by default"}),"\n",(0,a.jsxs)(e.p,{children:["In most applications you won't want to configure tracing for each field. Instead you can use the\n",(0,a.jsx)(e.code,{children:"tracing.default"})," to enable tracing for specific types of fields."]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { wrapResolver, isRootField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"boolean"})," | { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"formatMessage"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsxs)(e.span,{className:"hljs-params",children:["duration: ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"number"})]}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"string"})," };\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Here we enable tracing for root fields"}),"\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config)\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolve"}),") =>"]})," resolve, ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// actual tracing wrappers will be described below"}),"\n  },\n});\n"]})}),"\n",(0,a.jsx)(e.p,{children:"There are a number of utility functions for detecting certain types of fields. For most applications\ntracing every resolver will add significant overhead with very little benefit. The following\nutilities exported by the tracing plugin can be used to determine which fields should have tracing\nenabled by default."}),"\n",(0,a.jsxs)(e.ul,{children:["\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"isRootField"}),": Returns true for fields of the ",(0,a.jsx)(e.code,{children:"Query"}),", ",(0,a.jsx)(e.code,{children:"Mutation"}),", and ",(0,a.jsx)(e.code,{children:"Subscription"})," types"]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"isScalarField"}),": Returns true for fields that return Scalars, or lists of scalars"]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"isEnumField"}),": Returns true for fields that return an Enum or list of Enums"]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"isExposedField"}),": Returns true for fields defined with the ",(0,a.jsx)(e.code,{children:"t.expose*"})," field builder methods, or\nfields that use the ",(0,a.jsx)(e.code,{children:"defaultFieldResolver"}),"."]}),"\n"]}),"\n",(0,a.jsx)(e.h3,{id:"implementing-a-tracer",children:"Implementing a tracer"}),"\n",(0,a.jsxs)(e.p,{children:["Tracers work by wrapping the execution of resolver calls. The ",(0,a.jsx)(e.code,{children:"tracing.wrap"})," function keeps this\nprocess as minimal as possible by simply providing the resolver for a field, and expecting a wrapped\nversion of the resolver to be returned. Resolvers can throw errors or return promises, and correctly\nhandling these edge cases can be a little complicated so the tracing plugin also comes with some\nhelpers utilities to simplify this process."]}),"\n",(0,a.jsxs)(e.p,{children:[(0,a.jsx)(e.code,{children:"tracing.wrap"})," takes 3 arguments:"]}),"\n",(0,a.jsxs)(e.ol,{children:["\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"resolver"}),": the resolver for a field"]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"options"}),": the tracing options for the field (set either on the field, or returned by\n",(0,a.jsx)(e.code,{children:"tracing.default"}),")."]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"fieldConfig"}),": A config object that describes the field being wrapped"]}),"\n"]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"boolean"})," | { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"formatMessage"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsxs)(e.span,{className:"hljs-params",children:["duration: ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"number"})]}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"string"})," };\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config),\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options, config"}),") =>"]}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"wrapResolver"}),"(resolver, ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"error, duration"}),") =>"]})," {\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," message =\n          ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"typeof"})," options === ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'object'"}),"\n            ? options.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"formatMessage"}),"(duration)\n            : ",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`Executed resolver ",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${config.parentType}"}),".",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${config.name}"})," in ",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${duration}"}),"ms`"]}),";\n\n        ",(0,a.jsx)(e.span,{className:"hljs-variable language_",children:"console"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"log"}),"(message);\n      }),\n  },\n});\n"]})}),"\n",(0,a.jsxs)(e.p,{children:["The ",(0,a.jsx)(e.code,{children:"wrapResolver"})," utility takes a resolver, and a ",(0,a.jsx)(e.code,{children:"onEnd"})," callback, and returns a wrapped version\nof the resolver that will call the callback with an error (or null) and the duration the resolver\ntook to complete."]}),"\n",(0,a.jsxs)(e.p,{children:["The ",(0,a.jsx)(e.code,{children:"runFunction"})," helper is similar, but rather than wrapping a resolver, will immediately execute a\nfunction with no arguments. This can be useful for more complex use cases where you need access to\nother resolver arguments, or want to add your own logic before the resolver begins executing."]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"boolean"})," | { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"formatMessage"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsxs)(e.span,{className:"hljs-params",children:["duration: ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"number"})]}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"string"})," };\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config) || (!",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isScalarField"}),"(config) && !",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isEnumField"}),"(config)),\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"source, args, ctx, info"}),") =>"]})," {\n      ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"doSomethingFirst"}),"(args);\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"runFunction"}),"(\n        ",(0,a.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"resolver"}),"(source, args, ctx, info),\n        ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"error, duration"}),") =>"]})," {\n          ",(0,a.jsx)(e.span,{className:"hljs-variable language_",children:"console"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"log"}),"(\n            ",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`Executed resolver for ",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${info.parentType}"}),".",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${info.fieldName}"})," in ",(0,a.jsx)(e.span,{className:"hljs-subst",children:"${duration}"}),"ms`"]}),",\n          );\n        },\n      );\n    },\n  },\n});\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"using-resolver-arguments-in-tracers",children:"Using resolver arguments in tracers"}),"\n",(0,a.jsx)(e.p,{children:"When defining tracing options for a field, you may want to pass some resolver args to your tracing\nlogic."}),"\n",(0,a.jsx)(e.p,{children:"The follow example shows how arguments might be passed to a tracer to be attached to a span:"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Create a simple tracer that creates spans, and adds custom attributes if they are provided"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"})," | { attributes?: ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Record"}),"<",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"string"}),", ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"unknown"}),"> };\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," {\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config)) {\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," {};\n      }\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"}),";\n    },\n    ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// The `tracing` options are passed as the second argument for wrap"}),"\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options, fieldConfig"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"source, args, ctx, info"}),") =>"]})," {\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," span = tracer.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createSpan"}),"();\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"attributes"}),") {\n        span.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setAttributes"}),"();\n      }\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"runFunction"}),"(\n        ",(0,a.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"resolver"}),"(source, args, ctx, info),\n        ",(0,a.jsx)(e.span,{className:"hljs-function",children:"() =>"})," {\n          span.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"end"}),"();\n        },\n      );\n    },\n  },\n});\n\nbuilder.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"queryType"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"t"}),") =>"]})," ({\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"hello"}),": t.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"({\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"args"}),": { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"name"}),": t.",(0,a.jsx)(e.span,{className:"hljs-property",children:"arg"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"() },\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Pass this fields args as a custom attribute"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"root, args"}),") =>"]})," ({ ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"attributes"}),": { args } }),\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"resolve"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"root, { name }"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`hello, ",(0,a.jsxs)(e.span,{className:"hljs-subst",children:["${name || ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'World'"}),"}"]}),"`"]}),",\n    }),\n  }),\n});\n"]})}),"\n",(0,a.jsxs)(e.p,{children:["The ",(0,a.jsx)(e.code,{children:"default"})," option can also return a function to access resolver arguments:"]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Create a simple tracer that creates spans, and adds custom attributes if they are provided"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"})," | { attributes?: ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Record"}),"<",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"string"}),", ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"unknown"}),"> };\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," {\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config)) {\n        ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// For all root fields, add arguments as a custom attribute"}),"\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"root, args"}),") =>"]})," ({ ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"attributes"}),": { args }});\n      }\n\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// disable tracing for exposed fields"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isExposedField"}),"(config)) {\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"}),"\n      }\n\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Enable tracing, but don't add any attributes"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," {}\n    },\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ...,\n});\n"]})}),"\n",(0,a.jsxs)(e.p,{children:["It is important to know that if a field uses a function to return its tracing option (either\ndirectly on the field definition, or as a default) the behavior of the ",(0,a.jsx)(e.code,{children:"wrap"})," function changes\nslightly."]}),"\n",(0,a.jsxs)(e.p,{children:["By default ",(0,a.jsx)(e.code,{children:"wrap"})," is called for each field when the schema is built. For fields that return their\ntracing option via a function, wrap will be called whenever the field is executed because the\ntracing options are dependent on the resolver arguments."]}),"\n",(0,a.jsx)(e.p,{children:"For many uses cases this does not add a lot of overhead, but as a rule of thumb, it is always more\nefficient to use tracing options that don't depend on the resolver value."}),"\n",(0,a.jsx)(e.p,{children:"The above example could be re-designed slightly to improve tracing performance:"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Create a simple tracer that creates spans, and adds custom attributes if they are provided"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"})," | { includeArgs?: ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"boolean"})," };\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," {\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config)) {\n        ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// For all root fields, add arguments as a custom attribute"}),"\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeArgs"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"})," }\n      }\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"}),"\n    },\n    ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Wrap is now only called once for each field at build time"}),"\n    ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// since we don't depend on args to generate the tracing options"}),"\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options, fieldConfig"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"source, args, ctx, info"}),") =>"]})," {\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," span = tracer.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createSpan"}),"();\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"includeArgs"}),") {\n        span.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setAttributes"}),"({ args });\n      }\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"runFunction"}),"(\n        ",(0,a.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"resolver"}),"(source, args, ctx, info),\n        ",(0,a.jsx)(e.span,{className:"hljs-function",children:"() =>"})," {\n          span.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"end"}),"();\n        },\n      );\n    },,\n});\n"]})}),"\n",(0,a.jsx)(e.h2,{id:"tracing-integrations",children:"Tracing integrations"}),"\n",(0,a.jsx)(e.h3,{id:"opentelemetry",children:"Opentelemetry"}),"\n",(0,a.jsx)(e.h4,{id:"install-1",children:"install"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"hljs language-bash",children:"yarn add @pothos/tracing-opentelemetry @opentelemetry/semantic-conventions @opentelemetry/api\n"})}),"\n",(0,a.jsx)(e.h4,{id:"basic-usage",children:"Basic usage"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/core'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { isRootField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createOpenTelemetryWrapper } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-opentelemetry'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { tracer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./tracer'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," createSpan = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createOpenTelemetryWrapper"}),"(tracer, {\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeSource"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config),\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createSpan"}),"(resolver, options),\n  },\n});\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"options",children:"options"}),"\n",(0,a.jsxs)(e.ul,{children:["\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeArgs"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeSource"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"ignoreError"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"onSpan"}),": ",(0,a.jsx)(e.code,{children:"(span, tracingOptions, parent, args, context, info) => void"})]}),"\n"]}),"\n",(0,a.jsx)(e.h4,{id:"adding-custom-attributes-to-spans",children:"Adding custom attributes to spans"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeValue"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/api'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/core'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { isRootField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createOpenTelemetryWrapper } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-opentelemetry'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { tracer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./tracer'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"type"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingOptions"})," = ",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"boolean"})," | { attributes?: ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Record"}),"<",(0,a.jsx)(e.span,{className:"hljs-built_in",children:"string"}),", ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeValue"}),"> };\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," createSpan = createOpenTelemetryWrapper<",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingOptions"}),">(tracer, {\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeSource"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"onSpan"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"span, options"}),") =>"]})," {\n    ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"typeof"})," options === ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'object'"})," && options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"attributes"}),") {\n      span.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setAttributes"}),"(options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"attributes"}),");\n    }\n  },\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Tracing"}),": ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingOptions"}),";\n}>({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config),\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createSpan"}),"(resolver, options),\n  },\n});\n\nbuilder.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"queryType"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"t"}),") =>"]})," ({\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"hello"}),": t.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"({\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"args"}),": { ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"name"}),": t.",(0,a.jsx)(e.span,{className:"hljs-property",children:"arg"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"string"}),"() },\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"parent, { name }"}),") =>"]})," ({ ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"attributes"}),": { name } }),\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"resolve"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"parent, { name }"}),") =>"]})," ",(0,a.jsxs)(e.span,{className:"hljs-string",children:["`hello, ",(0,a.jsxs)(e.span,{className:"hljs-subst",children:["${name || ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'World'"}),"}"]}),"`"]}),",\n    }),\n  }),\n});\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"instrumenting-the-execution-phase",children:"Instrumenting the execution phase"}),"\n",(0,a.jsx)(e.p,{children:"The tracing plugin for Pothos only adds spans for resolvers. You may also want to capture additional\ninformation about other parts of the graphql execution process."}),"\n",(0,a.jsx)(e.p,{children:"This example uses GraphQL Yoga, by providing a custom envelop plugin that wraps the execution phase.\nMany graphql server implementations have ways to wrap or replace the execution call, but will look\nslightly different."}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-comment",children:"// eslint-disable-next-line simple-import-sort/imports"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { tracer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./tracer'"}),"; ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Tracer should be imported first if it handles additional instrumentation"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { print } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createYoga, ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql-yoga'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createServer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'node:http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),", ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SpanNames"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-opentelemetry'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { schema } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./schema'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracingPlugin"}),": ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," = {\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"onExecute"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"{ setExecuteFn, executeFn }"}),") =>"]})," {\n    ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setExecuteFn"}),"(",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"options"}),") =>"]}),"\n      tracer.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"startActiveSpan"}),"(\n        ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SpanNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"EXECUTE"}),",\n        {\n          ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"attributes"}),": {\n            [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"OPERATION_NAME"}),"]: options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"operationName"})," ?? ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"undefined"}),",\n            [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"SOURCE"}),"]: ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"print"}),"(options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"document"}),"),\n          },\n        },\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"async"})," (span) => {\n          ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"try"})," {\n            ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," result = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"await"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"executeFn"}),"(options);\n\n            ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," result;\n          } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"catch"})," (error) {\n            span.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"recordException"}),"(error ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"as"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Error"}),");\n            ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"throw"})," error;\n          } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"finally"})," {\n            span.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"end"}),"();\n          }\n        },\n      ),\n    );\n  },\n};\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," yoga = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createYoga"}),"({\n  schema,\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [tracingPlugin],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," server = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createServer"}),"(yoga);\n"]})}),"\n",(0,a.jsxs)(e.p,{children:["Envelop also provides its own opentelemetry plugin which can be used instead of a custom plugin like\nthe one shown above. The biggest drawback to this is the current version of ",(0,a.jsx)(e.code,{children:"@envelop/opentelemetry"}),"\ndoes not track the parent/child relations of spans it creates."]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { provider } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./tracer'"}),"; ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Tracer should be imported first if it handles additional instrumentation"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { useOpenTelemetry } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@envelop/opentelemetry'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createYoga } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql-yoga'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createServer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'node:http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { schema } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./schema'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," yoga = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createYoga"}),"({\n  schema,\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [\n    ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"useOpenTelemetry"}),"(\n      {\n        ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Disabling envelops resolver tracing is important to avoid duplicate spans"}),"\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"resolvers"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"}),",\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"variables"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"}),",\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"result"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"}),",\n      },\n      provider,\n    ),\n  ],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," server = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createServer"}),"(yoga);\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"setting-up-a-tracer",children:"Setting up a tracer"}),"\n",(0,a.jsx)(e.p,{children:"The following setup creates a very simple opentelemetry tracer that will log spans to the console.\nReal applications will need to define exporters that match the opentelemetry backend you are using."}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { diag, ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"DiagConsoleLogger"}),", ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"DiagLogLevel"}),", trace } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/api'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { registerInstrumentations } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/instrumentation'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"HttpInstrumentation"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/instrumentation-http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"ConsoleSpanExporter"}),", ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SimpleSpanProcessor"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/sdk-trace-base'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"NodeTracerProvider"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/sdk-trace-node'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," provider = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"NodeTracerProvider"}),"({});\nprovider.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"addSpanProcessor"}),"(",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SimpleSpanProcessor"}),"(",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"ConsoleSpanExporter"}),"()));\nprovider.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"register"}),"();\n\n",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"registerInstrumentations"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Automatically create spans for http requests"}),"\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"instrumentations"}),": [",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"HttpInstrumentation"}),"({})],\n});\n\ndiag.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setLogger"}),"(",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"DiagConsoleLogger"}),"(), ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"DiagLogLevel"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"INFO"}),");\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," tracer = trace.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"getTracer"}),"(",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql'"}),");\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"datadog",children:"Datadog"}),"\n",(0,a.jsx)(e.p,{children:"Datadog supports opentelemetry. To report traces to datadog, you will need to instrument your\napplication with an opentelemetry tracer, and configure your datadog agent to collect open telemetry\ntraces."}),"\n",(0,a.jsx)(e.h4,{id:"creating-a-tracer-that-exports-to-datadog",children:"Creating a tracer that exports to datadog"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { trace } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/api'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"OTLPTraceExporter"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/exporter-trace-otlp-http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { registerInstrumentations } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/instrumentation'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"HttpInstrumentation"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/instrumentation-http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Resource"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/resources'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SimpleSpanProcessor"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/sdk-trace-base'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"NodeTracerProvider"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/sdk-trace-node'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SemanticResourceAttributes"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@opentelemetry/semantic-conventions'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," provider = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"NodeTracerProvider"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"resource"}),": ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Resource"}),"({\n    [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SemanticResourceAttributes"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"SERVICE_NAME"}),"]: ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'Pothos-OTEL-example'"}),",\n  }),\n});\n\nprovider.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"addSpanProcessor"}),"(\n  ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SimpleSpanProcessor"}),"(\n    ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"OTLPTraceExporter"}),"({\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// optionally set the opentelemetry collector endpoint if you are not using the default port"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// url: 'http://host:port',"}),"\n    }),\n  ),\n);\n\nprovider.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"register"}),"();\n\n",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"registerInstrumentations"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"instrumentations"}),": [",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"HttpInstrumentation"}),"({})],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," tracer = trace.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"getTracer"}),"(",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql'"}),");\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"configuring-the-datadog-agent-to-collect-open-telemetry",children:"Configuring the datadog agent to collect open telemetry"}),"\n",(0,a.jsx)(e.p,{children:"Add the following to your datadog agent configuration"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-yaml",children:[(0,a.jsx)(e.span,{className:"hljs-attr",children:"otlp_config:"}),"\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"receiver:"}),"\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"protocols:"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"http:"}),"\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"endpoint:"})," ",(0,a.jsx)(e.span,{className:"hljs-number",children:"0.0"}),(0,a.jsx)(e.span,{className:"hljs-number",children:".0"}),(0,a.jsx)(e.span,{className:"hljs-number",children:".0"}),(0,a.jsx)(e.span,{className:"hljs-string",children:":4318"}),"\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"new-relic",children:"New Relic"}),"\n",(0,a.jsx)(e.h4,{id:"install-2",children:"install"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"hljs language-bash",children:"yarn add @pothos/tracing-newrelic newrelic @types/newrelic\n"})}),"\n",(0,a.jsx)(e.h4,{id:"basic-usage-1",children:"Basic usage"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/core'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { isRootField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createNewrelicWrapper } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-newrelic'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," wrapResolver = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createNewrelicWrapper"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeArgs"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeSource"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config),\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"wrapResolver"}),"(resolver),\n  },\n});\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"options-1",children:"options"}),"\n",(0,a.jsxs)(e.ul,{children:["\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeArgs"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeSource"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n"]}),"\n",(0,a.jsx)(e.h4,{id:"instrumenting-the-execution-phase-1",children:"Instrumenting the execution phase"}),"\n",(0,a.jsx)(e.p,{children:"The tracing plugin for Pothos only adds spans for resolvers. You may also want to capture additional\ninformation about other parts of the graphql execution process."}),"\n",(0,a.jsx)(e.p,{children:"This example uses GraphQL Yoga, by providing a custom envelop plugin that wraps the execution phase.\nMany graphql server implementations have ways to wrap or replace the execution call, but will look\nslightly different."}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-comment",children:"// eslint-disable-next-line simple-import-sort/imports"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," newrelic ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'newrelic'"}),"; ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// newrelic must be imported first"}),"\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { print } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createYoga, ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql-yoga'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createServer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'node:http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-newrelic'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { schema } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./schema'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracingPlugin"}),": ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," = {\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"onExecute"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"{ args }"}),") =>"]})," {\n    newrelic.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"addCustomAttributes"}),"({\n      [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"OPERATION_NAME"}),"]: args.",(0,a.jsx)(e.span,{className:"hljs-property",children:"operationName"})," ?? ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'<unnamed operation>'"}),",\n      [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"SOURCE"}),"]: ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"print"}),"(args.",(0,a.jsx)(e.span,{className:"hljs-property",children:"document"}),"),\n    });\n  },\n};\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," yoga = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createYoga"}),"({\n  schema,\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [tracingPlugin],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," server = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createServer"}),"(yoga);\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"using-the-envelop-newrelic-plugin",children:"Using the envelop newrelic plugin"}),"\n",(0,a.jsx)(e.p,{children:"Envelop has it's own plugin for newrelic that can be combined with the tracing plugin:"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { useNewRelic } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@envelop/newrelic'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createYoga } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql-yoga'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createServer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'node:http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { schema } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./schema'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," yoga = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createYoga"}),"({\n  schema,\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [\n    ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"useNewRelic"}),"({\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// Disable resolver tracking since this is covered by the pothos tracing plugin"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-comment",children:"// If all resolvers are being traced, you could use the New Relic envelop plug instead of the pothos tracing plugin"}),"\n      ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"trackResolvers"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"false"}),",\n    }),\n  ],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," server = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createServer"}),"(yoga);\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"sentry",children:"Sentry"}),"\n",(0,a.jsx)(e.h4,{id:"install-3",children:"install"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"hljs language-bash",children:"yarn add @pothos/tracing-sentry @sentry/node @sentry/tracing\n"})}),"\n",(0,a.jsx)(e.h4,{id:"basic-usage-2",children:"Basic usage"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/core'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { isRootField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createSentryWrapper } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-sentry'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," traceResolver = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createSentryWrapper"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeArgs"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeSource"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config),\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"traceResolver"}),"(resolver, options),\n  },\n});\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"options-2",children:"options"}),"\n",(0,a.jsxs)(e.ul,{children:["\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeArgs"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeSource"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"ignoreError"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n"]}),"\n",(0,a.jsx)(e.h4,{id:"instrumenting-the-execution-phase-2",children:"Instrumenting the execution phase"}),"\n",(0,a.jsx)(e.p,{children:"The tracing plugin for Pothos only adds spans for resolvers. You may also want to capture additional\ninformation about other parts of the graphql execution process."}),"\n",(0,a.jsx)(e.p,{children:"This example uses GraphQL Yoga, by providing a custom envelop plugin that wraps the execution phase.\nMany graphql server implementations have ways to wrap or replace the execution call, but will look\nslightly different."}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@sentry/tracing'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { print } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createYoga, ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql-yoga'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createServer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'node:http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-sentry'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," * ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"as"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Sentry"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@sentry/node'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { schema } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./schema'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Sentry"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"init"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"dsn"}),": process.",(0,a.jsx)(e.span,{className:"hljs-property",children:"env"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"SENTRY_DSN"}),",\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracesSampleRate"}),": ",(0,a.jsx)(e.span,{className:"hljs-number",children:"1"}),",\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracingPlugin"}),": ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," = {\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"onExecute"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"{ setExecuteFn, executeFn }"}),") =>"]})," {\n    ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setExecuteFn"}),"(",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"async"})," (options) => {\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," transaction = ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Sentry"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"startTransaction"}),"({\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"op"}),": ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql.execute'"}),",\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"name"}),": options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"operationName"})," ?? ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'<unnamed operation>'"}),",\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tags"}),": {\n          [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"OPERATION_NAME"}),"]: options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"operationName"})," ?? ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"undefined"}),",\n          [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"SOURCE"}),"]: ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"print"}),"(options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"document"}),"),\n        },\n        ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"data"}),": {\n          [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"SOURCE"}),"]: ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"print"}),"(options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"document"}),"),\n        },\n      });\n      ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Sentry"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"getCurrentHub"}),"().",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"configureScope"}),"(",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"scope"}),") =>"]})," scope.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setSpan"}),"(transaction));\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"try"})," {\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," result = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"await"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"executeFn"}),"(options);\n\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," result;\n      } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"finally"})," {\n        transaction.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"finish"}),"();\n      }\n    });\n  },\n};\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," yoga = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createYoga"}),"({\n  schema,\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [tracingPlugin],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," server = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createServer"}),"(yoga);\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"using-the-envelop-sentry-plugin",children:"Using the envelop sentry plugin"}),"\n",(0,a.jsx)(e.p,{children:"Envelop has it's own plugin for Sentry that can be combined with the tracing plugin:"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { useSentry } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@envelop/sentry'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createYoga } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql-yoga'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createServer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'node:http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { schema } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./schema'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," yoga = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createYoga"}),"({\n  schema,\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"useSentry"}),"({})],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," server = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createServer"}),"(yoga);\n"]})}),"\n",(0,a.jsx)(e.h3,{id:"aws-xray",children:"AWS XRay"}),"\n",(0,a.jsx)(e.h4,{id:"install-4",children:"install"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"hljs language-bash",children:"yarn add @pothos/tracing-xray aws-xray-sdk-core\n"})}),"\n",(0,a.jsx)(e.h4,{id:"basic-usage-3",children:"Basic usage"}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/core'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),", { isEnumField, isRootField, isScalarField } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-tracing'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createXRayWrapper } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-xray'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," traceResolver = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createXRayWrapper"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeArgs"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"includeSource"}),": ",(0,a.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," builder = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"({\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"TracingPlugin"}),"],\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracing"}),": {\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"default"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"config"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isRootField"}),"(config) || (!",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isScalarField"}),"(config) && !",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"isEnumField"}),"(config)),\n    ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"wrap"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"resolver, options"}),") =>"]})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"traceResolver"}),"(resolver, options),\n  },\n});\n"]})}),"\n",(0,a.jsx)(e.h4,{id:"options-3",children:"options"}),"\n",(0,a.jsxs)(e.ul,{children:["\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeArgs"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n",(0,a.jsxs)(e.li,{children:[(0,a.jsx)(e.code,{children:"includeSource"}),": default: ",(0,a.jsx)(e.code,{children:"false"})]}),"\n"]}),"\n",(0,a.jsx)(e.h4,{id:"instrumenting-the-execution-phase-3",children:"Instrumenting the execution phase"}),"\n",(0,a.jsx)(e.p,{children:"The tracing plugin for Pothos only adds spans for resolvers. You may also want to capture additional\ninformation about other parts of the graphql execution process."}),"\n",(0,a.jsx)(e.p,{children:"This example uses GraphQL Yoga, by providing a custom envelop plugin that wraps the execution phase.\nMany graphql server implementations have ways to wrap or replace the execution call, but will look\nslightly different."}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsxs)(e.code,{className:"hljs language-ts",children:[(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AWSXRay"})," ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'aws-xray-sdk-core'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { print } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createYoga, ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'graphql-yoga'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { createServer } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'node:http'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),", ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SpanNames"})," } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'@pothos/tracing-xray'"}),";\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { schema } ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'./schema'"}),";\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"tracingPlugin"}),": ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Plugin"})," = {\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"onExecute"}),": ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"{ setExecuteFn, executeFn }"}),") =>"]})," {\n    ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setExecuteFn"}),"(",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"async"})," (options) => {\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," parent = ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AWSXRay"}),".",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"Segment"}),"(",(0,a.jsx)(e.span,{className:"hljs-string",children:"'parent'"}),");\n\n      ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AWSXRay"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"getNamespace"}),"().",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"runAndReturn"}),"(",(0,a.jsx)(e.span,{className:"hljs-function",children:"() =>"})," {\n        ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AWSXRay"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"setSegment"}),"(parent);\n\n        ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AWSXRay"}),".",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"captureAsyncFunc"}),"(\n          ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"SpanNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"EXECUTE"}),",\n          ",(0,a.jsxs)(e.span,{className:"hljs-function",children:["(",(0,a.jsx)(e.span,{className:"hljs-params",children:"segment"}),") =>"]})," {\n            ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"if"})," (segment) {\n              segment.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"addAttribute"}),"(\n                ",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"OPERATION_NAME"}),",\n                options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"operationName"})," ?? ",(0,a.jsx)(e.span,{className:"hljs-string",children:"'<unnamed operation>'"}),",\n              );\n              segment.",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"addAttribute"}),"(",(0,a.jsx)(e.span,{className:"hljs-title class_",children:"AttributeNames"}),".",(0,a.jsx)(e.span,{className:"hljs-property",children:"SOURCE"}),", ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"print"}),"(options.",(0,a.jsx)(e.span,{className:"hljs-property",children:"document"}),"));\n            }\n\n            ",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"return"})," ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"executeFn"}),"(options);\n          },\n          parent,\n        );\n      });\n    });\n  },\n};\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," yoga = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createYoga"}),"({\n  schema,\n  ",(0,a.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [tracingPlugin],\n});\n\n",(0,a.jsx)(e.span,{className:"hljs-keyword",children:"const"})," server = ",(0,a.jsx)(e.span,{className:"hljs-title function_",children:"createServer"}),"(yoga);\n"]})})]})}e.default=function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,a.jsx)(t,Object.assign({},s,{children:(0,a.jsx)(h,s)}))}}},function(s){s.O(0,[8430,3210,9774,2888,179],function(){return s(s.s=4970)}),_N_E=s.O()}]);