Skip to content

Commit

Permalink
Merge pull request #15 from dataforgoodfr/feat/tracer_init
Browse files Browse the repository at this point in the history
Double initialization
  • Loading branch information
samuelrince authored Mar 19, 2024
2 parents 283811f + b687a42 commit 1316e3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions genai_impact/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class GenAIImpactError(Exception):
pass

class TracerInitializationError(GenAIImpactError):
"Tracer is initialized twice"
pass
8 changes: 6 additions & 2 deletions genai_impact/tracer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import importlib.util

from genai_impact.exceptions import TracerInitializationError

class Tracer:

class Tracer:
initialized = False
@staticmethod
def init() -> None:
if Tracer.initialized:
raise TracerInitializationError()
init_instruments()

Tracer.initialized = True

def init_instruments() -> None:
init_openai_instrumentor()
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tracer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest
from genai_impact import Tracer
from genai_impact.exceptions import GenAIImpactError

def test_double_init(tracer_init):
with pytest.raises(GenAIImpactError) as e:
Tracer.init() # Second initialization

0 comments on commit 1316e3a

Please sign in to comment.