Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logfire to the project #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cat_bacon/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.shortcuts import render, redirect, get_object_or_404

from openai import Client
import logfire

from .forms import ImageForm
from .models import Image
Expand All @@ -16,12 +17,13 @@ def index(request):
if request.method == 'POST':
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
image_file, image_url = create_image(client, form.instance.animal, form.instance.artist)
print(f'image_file: {image_file!r}, image_url: {image_url!r}')
form.instance.file_path = image_file
form.instance.url = image_url
image = form.save()
return redirect('image-details', image_id=image.id)
with logfire.span('create_image {artist=}', artist=form.instance.artist) as span:
image_file, image_url = create_image(client, form.instance.animal, form.instance.artist)
span.set_attributes(dict(image_file=image_file, image_url=image_url))
form.instance.file_path = image_file
form.instance.url = image_url
image = form.save()
return redirect('image-details', image_id=image.id)
else:
form = ImageForm()

Expand Down
8 changes: 8 additions & 0 deletions logfire_django_demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

import logfire

logfire.configure()
logfire.instrument_django()
logfire.instrument_httpx()
logfire.instrument_openai()
logfire.instrument_psycopg()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dependencies = [
"openai>=1.44.1",
"httpx>=0.27.2",
"psycopg>=3.2.1",
"logfire[django,httpx,openai,pyscopg]>=0.52.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psycopg is mispelled

]
Loading