Skip to content

Commit

Permalink
feat: Add graphql-core instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dacevedo12 committed Nov 19, 2023
1 parent c08b762 commit f40653d
Show file tree
Hide file tree
Showing 12 changed files with 748 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ jobs:
with:
set-safe-directory: /github/workspace
args: sh -c "chown -R root:root /github/workspace && m . /lintPython/module/aiobotocore"
lintPython_module_graphql_core:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker://ghcr.io/fluidattacks/makes/amd64:latest
with:
set-safe-directory: /github/workspace
args: sh -c "chown -R root:root /github/workspace && m . /lintPython/module/graphql_core"
name: dev
on:
push:
Expand Down
65 changes: 65 additions & 0 deletions otelcontribs/instrumentation/graphql_core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# OpenTelemetry Instrumentation for graphql-core

[![PyPI version](https://badge.fury.io/py/otelcontribs-instrumentation-graphql-core.svg)](https://badge.fury.io/py/otelcontribs-instrumentation-graphql-core)

This library allows tracing the parsing, validation and execution of queries performed by [graphql-core](https://pypi.org/project/graphql-core).

## Installation

```bash
pip install otelcontribs-instrumentation-graphql-core
```

## Usage

Programmatically enable instrumentation via the following code:

```python
# Instrument GraphQL-core
from otelcontribs.instrumentation.graphql_core import GraphQLCoreInstrumentor

GraphQLCoreInstrumentor().instrument()

# This will create a span with GraphQL-specific attributes
from graphql import (
GraphQLField,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
graphql,
)

def resolve_hello(parent, info):
return "Hello world!"

schema = GraphQLSchema(
query=GraphQLObjectType(
name="RootQueryType",
fields={
"hello": GraphQLField(GraphQLString, resolve=resolve_hello)
},
)
)

await graphql(schema, "{ hello }")
```

## API

The `instrument` method accepts the following keyword args:

- tracer_provider (TracerProvider) - an optional tracer provider
- skip_default_resolvers (Boolean) - whether to skip spans for default resolvers. True by default
- skip_introspection_query (Boolean) - whether to skip introspection queries. True by default

for example:

```python
# Instrument GraphQL-core
from otelcontribs.instrumentation.graphql_core import GraphQLCoreInstrumentor

GraphQLCoreInstrumentor().instrument(
skip_default_resolvers=False,
skip_introspection_query=False,
)
```
Loading

0 comments on commit f40653d

Please sign in to comment.