sikanhe / apollo-tracing-elixir Goto Github PK
View Code? Open in Web Editor NEWApollo Tracing middleware for Absinthe
Apollo Tracing middleware for Absinthe
Hello! Curious if it would be possible to bump this dep as it's locked into a very specific version and freazing our dep update effort.
Thank you!
Failed to use "jason" (version 1.2.1) because
apollo_tracing (version 0.4.3) requires ~> 1.1.2
hi there ~
when i use jason as json_codec, an error broke the test:
defmodule GroupherServerWeb.Router do
@moduledoc false
# ...
scope "/graphiql" do
pipe_through(:api)
forward(
"/",
Absinthe.Plug.GraphiQL,
schema: GroupherServerWeb.Schema,
json_codec: Jason,
pipeline: {ApolloTracing.Pipeline, :plug},
interface: :playground,
context: %{pubsub: GroupherServerWeb.Endpoint}
)
end
end
** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for %ApolloTracing.Schema{duration: nil, endTime: nil, execution: %ApolloTracing.Schema.Execution{resolvers: []}, startTime: "2019-07-11T13:40:41.969305Z", version: 1} of type ApolloTracing.Schema (a struct), Jason.Encoder protocol must always be explicitly implemented.
If you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:
@derive {Jason.Encoder, only: [....]}
defstruct ...
It is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:
@derive Jason.Encoder
defstruct ...
Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:
Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
Protocol.derive(Jason.Encoder, NameOfTheStruct)
. This protocol is implemented for the following type(s): Ecto.Association.NotLoaded, Ecto.Schema.Metadata, Date, BitString, Jason.Fragment, Any, Map, NaiveDateTime, List, Integer, Time, DateTime, Decimal, Atom, Float
is jason not supported ?
to work around, i had to add those two line according to the error hint
Protocol.derive(Jason.Encoder, ApolloTracing.Schema)
Protocol.derive(Jason.Encoder, ApolloTracing.Schema.Execution)
ie: :string
into "String"
,list_of(:string)
into "[String]"
Because tracing shows up in the return value, there should probably be a good way to tracing on or off. If you're testing your API for example you don't want to have to be dropping the extensions key from the result all the time.
It may also be a valuable production flag if for some reason things are going weirdly and tracing is causing a performance issue. It may be enough to add a simple application environment variable.
Any suggestions on setting up tracing for websocket?
Not entirely sure if this due to apollo-tracing
, but I'm receiving this :resolution not found in: %Absinthe.Blueprint
error. Here are my GraphQL related deps:
{:absinthe, "~> 1.4.0-rc.3", override: true},
{:absinthe_plug, "~> 1.4.0-rc.1"},
{:absinthe_ecto, "~> 0.1.2"},
{:absinthe_phoenix, github: "absinthe-graphql/absinthe_phoenix"},
{:apollo_tracing, git: "https://github.com/sikanhe/apollo-tracing-elixir.git"},
If I remove tracing from the pipeline, no errors (which makes me think the error originates from this module). It can be hard to track down since I'm a little fuzzy on how all the related modules interrelate. Also note, I'm using sockets as well (which don't pass through tracing), and that works.
I believe I had this working with a previous version of absinthe
and/or absinthe_plug
, but I'd rather keep up with the core module versions as tracing isn't mission critical.
Thoughts?
If I only add tracing to the absinthe pipeline, it works. If I add tracing to the absinthe pipeline and add use ApolloTracing
to my schema, I get the error below:
** (BadStructError) expected a struct named ApolloTracing.Schema.Execution.Resolver, got: %{duration: 4000, ...
My Absinthe related deps are:
{:absinthe, "~> 1.4.0-beta.3", override: true},
{:absinthe_plug, "~> 1.4.0-beta.2"},
{:absinthe_ecto, "~> 0.1.2"},
{:apollo_tracing, git: "https://github.com/sikanhe/apollo-tracing-elixir.git"}
Maybe worth noting, I couldn't get
apollo_tracing
to install without referencing the github repo directly. The absinthe override is to dueabsinthe_ecto
Problem:
absinthe_plug is a project dependency and the following error occurs during runtime making a request in a distillery release.
Description:
Request: POST /api
** (exit) an exception was raised:
** (RuntimeError) You don't have Plug loaded, please use
ApolloTracing.Pipeline.default(absinthe_schema, pipeline_opts)
to produce a pipeline without Plug specific phases
(apollo_tracing) lib/apollo_tracing/pipeline.ex:16: ApolloTracing.Pipeline.plug/2
(absinthe_plug) lib/absinthe/plug/request/query.ex:75: Absinthe.Plug.Request.Query.add_pipeline/3
It seems to be because Distillery doesn't find the Absinthe.Plug module...
if Code.ensure_loaded?(Absinthe.Plug) do
def plug(config, pipeline_opts \\ []) do
config
|> Absinthe.Plug.default_pipeline(pipeline_opts)
|> add_phases()
end
else
def plug(_, _ \\ []) do
raise RuntimeError, """
You don't have Plug loaded, please use
ApolloTracing.Pipeline.default(absinthe_schema, pipeline_opts)
to produce a pipeline without Plug specific phases
"""
end
end
One Possible Solution:
Relates to PR
Absinthe 1.4 added support for GraphQL subscriptions, as well as a support module for testing them. This module primes absinthe to load eagerly by running the schema with the default pipeline, so that subscription tests with a short timeout can pass. Unfortunately this does not allow apollo_tracing to add its metadata, so the middleware fails to successfully pattern match when called (https://github.com/sikanhe/apollo-tracing-elixir/blob/master/lib/apollo_tracing/middleware.ex#L10)
Hi there, just checking. Is this being maintained? What features are missing? Do you need help?
[deleted]
Now that Engine is officially deprecated, it would be great to see support for sending metrics directly to the Apollo Platform from this library.
There's no official documentation yet, but this is a good start:
https://github.com/apollographql/apollo/pull/263/files
Currently we use path info inside Resolution for "path", but the spec requires indexes for items inside a list.
Links to apollo website are broken in the readme.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.