Skip to content
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
2 changes: 2 additions & 0 deletions sdk-api/logging/galileo-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import SnippetSdkLoggingContextSimpleWithLogPythonBeta from "/snippets/code/pyth
import SnippetSdkLoggingContextSimpleWithOpenAIPython from "/snippets/code/python/sdk/logging/context-simple-with-openai.mdx";
import SnippetSdkLoggingContextSimpleWithOpenAIPythonBeta from "/snippets/code/python-beta/sdk/logging/context-simple-with-openai.mdx";
import SnippetSdkLoggingNestingScopesPython from "/snippets/code/python/sdk/logging/nesting-scopes.mdx";
import SnippetSdkLoggingNestingScopesPythonBeta from "/snippets/code/python-beta/sdk/logging/nesting-scopes.mdx";
import SnippetSdkLoggingContextNewSessionPython from "/snippets/code/python/sdk/logging/context-new-session.mdx";
import SnippetSdkLoggingContextNewSessionExternalIdPython from "/snippets/code/python/sdk/logging/context-new-session-external-id.mdx";
import SnippetSdkLoggingContextContinueSessionPython from "/snippets/code/python/sdk/logging/context-continue-session.mdx";
Expand Down Expand Up @@ -83,6 +84,7 @@ You can nest `galileo_context` calls to temporarily override the project or Log

<CodeGroup>
<SnippetSdkLoggingNestingScopesPython />
<SnippetSdkLoggingNestingScopesPythonBeta />
</CodeGroup>

## Get the current logger
Expand Down
2 changes: 2 additions & 0 deletions sdk-api/logging/galileo-logger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SnippetSdkLoggingGetLoggerPython from "/snippets/code/python/sdk/logging/
import SnippetSdkLoggingGetLoggerDecoratorPython from "/snippets/code/python/sdk/logging/logger-from-context-log-decorator.mdx";
import SnippetSdkLoggingBasicLoggingPython from "/snippets/code/python/sdk/logging/basic-logging.mdx";
import SnippetSdkLoggingCreateLoggerPython from "/snippets/code/python/sdk/logging/create-logger.mdx";
import SnippetSdkLoggingCreateLoggerPythonBeta from "/snippets/code/python-beta/sdk/logging/create-logger.mdx";
import SnippetSdkLoggingStartLoggerSessionPython from "/snippets/code/python/sdk/logging/start-logger-session.mdx";
import SnippetSdkLoggingStartLoggerSessionMetadataPython from "/snippets/code/python/sdk/logging/start-logger-session-metadata.mdx";
import SnippetSdkLoggingStartLoggerSessionMetadataTypeScript from "/snippets/code/typescript/sdk/logging/start-logger-session-metadata.mdx";
Expand Down Expand Up @@ -109,6 +110,7 @@ This example:

<CodeGroup>
<SnippetSdkLoggingCreateLoggerPython />
<SnippetSdkLoggingCreateLoggerPythonBeta />
<SnippetSdkLoggingCreateLoggerTypeScript />
</CodeGroup>

Expand Down
2 changes: 2 additions & 0 deletions sdk-api/logging/log-decorator/log-decorator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SnippetLogDecoratorBasicUsagePython from "/snippets/code/python/sdk/decor
import SnippetLogDecoratorAdditionalParamsPython from "/snippets/code/python/sdk/decorators/log-decorator-additional-params.mdx";
import SnippetLogDecoratorMetadataTagsPython from "/snippets/code/python/sdk/decorators/log-decorator-metadata-tags.mdx";
import SnippetLogDecoratorContextManagementPython from "/snippets/code/python/sdk/decorators/log-decorator-context-management.mdx";
import SnippetLogDecoratorContextManagementPythonBeta from "/snippets/code/python-beta/sdk/decorators/log-decorator-context-management.mdx";
import SnippetLogDecoratorGeneratorsPython from "/snippets/code/python/sdk/decorators/log-decorator-generators.mdx";
import SnippetSdkWrappersOpenAILogDecoratorPython from "/snippets/code/python/sdk/wrappers/openai-log-decorator.mdx";

Expand Down Expand Up @@ -130,6 +131,7 @@ In Python, you can use the `galileo_context` to set the project and Log stream f

<CodeGroup>
<SnippetLogDecoratorContextManagementPython />
<SnippetLogDecoratorContextManagementPythonBeta />
</CodeGroup>

## Handling generators (Python)
Expand Down
4 changes: 4 additions & 0 deletions sdk-api/logging/logging-basics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description: Learn the basics of instrumenting your application with Galileo usi
import SnippetSdkLoggingContextInitPython from "/snippets/code/python/sdk/logging/context-init.mdx";
import SnippetSdkLoggingContextInitPythonBeta from "/snippets/code/python-beta/sdk/logging/context-init.mdx";
import SnippetSdkLoggingCreateLoggerWithProjectPython from "/snippets/code/python/sdk/logging/create-logger-with-project.mdx";
import SnippetSdkLoggingCreateLoggerWithProjectPythonBeta from "/snippets/code/python-beta/sdk/logging/create-logger-with-project.mdx";
import SnippetSdkLoggingContextGetLoggerPython from "/snippets/code/python/sdk/logging/context-get-logger.mdx";
import SnippetSdkLoggingContextGetLoggerPythonBeta from "/snippets/code/python-beta/sdk/logging/context-get-logger.mdx";

import SnippetSdkLoggingContextInitTypeScript from "/snippets/code/typescript/sdk/logging/context-init.mdx";
import SnippetSdkLoggingCreateLoggerWithProjectTypeScript from "/snippets/code/typescript/sdk/logging/create-logger-with-project.mdx";
Expand Down Expand Up @@ -96,13 +98,15 @@ To set the project and Log stream for a single logger, you can pass it to the lo

<CodeGroup>
<SnippetSdkLoggingCreateLoggerWithProjectPython />
<SnippetSdkLoggingCreateLoggerWithProjectPythonBeta />
<SnippetSdkLoggingCreateLoggerWithProjectTypeScript />
</CodeGroup>

You can also use the current context to get a logger for a particular project and Log stream.

<CodeGroup>
<SnippetSdkLoggingContextGetLoggerPython />
<SnippetSdkLoggingContextGetLoggerPythonBeta />
<SnippetSdkLoggingContextGetLoggerTypeScript />
</CodeGroup>

Expand Down
4 changes: 4 additions & 0 deletions sdk-api/logging/tags-and-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ description: Learn to use tags and metadata in Galileo logging and monitoring


import SnippetTagsAndMetadataPython1 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-1.mdx';
import SnippetTagsAndMetadataPythonBeta1 from '/snippets/code/python-beta/tags-and-metadata/tags-and-metadata-py-1.mdx';
import SnippetTagsAndMetadataPython2 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-2.mdx';
import SnippetTagsAndMetadataPython3 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-3.mdx';
import SnippetTagsAndMetadataPython4 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-4.mdx';
import SnippetTagsAndMetadataPython5 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-5.mdx';
import SnippetTagsAndMetadataPython6 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-6.mdx';
import SnippetTagsAndMetadataPython7 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-7.mdx';
import SnippetTagsAndMetadataPythonBeta7 from '/snippets/code/python-beta/tags-and-metadata/tags-and-metadata-py-7.mdx';
import SnippetTagsAndMetadataPython8 from '/snippets/code/python/tags-and-metadata/tags-and-metadata-py-8.mdx';

import SnippetTagsAndMetadataTypeScript1 from '/snippets/code/typescript/tags-and-metadata/tags-and-metadata-ts-1.mdx';
Expand Down Expand Up @@ -78,6 +80,7 @@ In this guide, we are building on top of the **finished demo application** from
[Log Your First Trace](/getting-started/quickstart) guide.
<CodeGroup>
<SnippetTagsAndMetadataPython1 />
<SnippetTagsAndMetadataPythonBeta1 />
<SnippetTagsAndMetadataTypeScript1 />
</CodeGroup>
</Step>
Expand Down Expand Up @@ -156,6 +159,7 @@ Below is the **final combined application code** for the
with our tags and metadata added to logged Traces and Spans.
<CodeGroup>
<SnippetTagsAndMetadataPython7 />
<SnippetTagsAndMetadataPythonBeta7 />
<SnippetTagsAndMetadataTypeScript7 />
</CodeGroup>
</Step>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```python Python (Beta)
from galileo import LogStream, log

@log
def my_function(input):
return f"Processed: {input}"

log_stream = LogStream.get(name="my-log-stream", project_name="my-project")

# This will log to the specified project and Log stream
with log_stream.context():
result = my_function("test input")
print(result)
```
9 changes: 9 additions & 0 deletions snippets/code/python-beta/sdk/logging/context-get-logger.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```python Python (Beta)
from galileo import LogStream, galileo_context

log_stream = LogStream.get(name="my-log-stream", project_name="my-project")

with log_stream.context():
# The logger picks up the project / Log stream from the active context
logger = galileo_context.get_logger_instance()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```python Python (Beta)
from galileo import GalileoLogger, LogStream

# Resolve (or create) the Log stream up front
log_stream = LogStream.get(name="my-log-stream", project_name="my-project")

# Route every logger created in this scope to that Log stream
with log_stream.context():
logger = GalileoLogger()
```
15 changes: 15 additions & 0 deletions snippets/code/python-beta/sdk/logging/create-logger.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```python Python (Beta)
from galileo import GalileoLogger, LogStream

# Initialize with default settings (uses environment variables)
logger = GalileoLogger()

# Or resolve a Log stream first and run logging inside its context
log_stream = LogStream.get(
name="my-log-stream",
project_name="my-project",
)

with log_stream.context():
logger = GalileoLogger()
```
17 changes: 17 additions & 0 deletions snippets/code/python-beta/sdk/logging/nesting-scopes.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```python Python (Beta)
from galileo import LogStream

main_stream = LogStream.get(name="my-log-stream", project_name="my-project")
sub_stream = LogStream.get(name="sub-stream", project_name="my-project")

with main_stream.context():
# This will log to my-project/my-log-stream
operation_1()

with sub_stream.context():
# This will log to my-project/sub-stream
operation_2()

# Back to logging to my-project/my-log-stream
operation_3()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```python Python (Beta)
from datetime import datetime
from galileo import galileo_context
from galileo import GalileoLogger, LogStream
from galileo.config import GalileoPythonConfig
import openai
from dotenv import load_dotenv

# Load environment variables from the .env file
load_dotenv()

# Resolve (or create) the Log stream — every logger created in this
# scope is routed to MyFirstTagandMetadata / MyFirstTagandMetatdata.
log_stream = LogStream.get(
name="MyFirstTagandMetatdata",
project_name="MyFirstTagandMetadata",
)
# Or create it if it does not exist:
# log_stream = LogStream(
# name="MyFirstTagandMetatdata",
# project_name="MyFirstTagandMetadata",
# ).create()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
```python Python (Beta)
from datetime import datetime
from galileo import galileo_context
from galileo import GalileoLogger, LogStream
from galileo.config import GalileoPythonConfig
import openai
from dotenv import load_dotenv

# Load environment variables from the .env file
load_dotenv()

# Resolve (or create) the Log stream up front
log_stream = LogStream.get(
name="MyFirstTagandMetatdata",
project_name="MyFirstTagandMetadata",
)

# All traces inside this block are routed to the Log stream above
with log_stream.context():
# Get the Galileo logger instance
logger = galileo_context.get_logger_instance()

# Start a Galileo session
logger.start_session()

# Initialize the OpenAI client
client = openai.OpenAI()

# Define a system prompt with guidance
system_prompt = f"""
You are a helpful assistant that wants to provide a user as much
information as possible. Avoid saying I don't know.
"""

# Define a user prompt with a question
user_prompt = f"Explain the following topic succinctly: Newton's First Law"

# Send a request to the LLM
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt},
],
)

# Print the response
print(response.choices[0].message.content.strip())

answer = response.choices[0].message.content.strip()

# Define tags and metadata
tags = ["newton", "test", "new-version"]
metadata = {
"experimentNumber": "1",
"promptVersion": "0.0.1",
"field": "physics",
}

# Initialize a new Trace and start listening for logs to add to it
trace = logger.start_trace(
input=user_prompt,
tags=tags,
metadata=metadata,
)

# Create a span to log LLM outputs. This is captured by the Trace.
logger.add_llm_span(
input=[{"role": "system", "content": user_prompt}],
output=response.choices[0].message.content,
model="gpt-4o",
tags=tags,
metadata=metadata,
)

# Close the Trace and push captured logs to it
logger.conclude(answer)
logger.flush()

# Show Galileo information after the response
config = GalileoPythonConfig.get()
project_url = f"{config.console_url}project/{logger.project_id}"
log_stream_url = f"{project_url}/log-streams/{logger.log_stream_id}"

print()
print("🚀 GALILEO LOG INFORMATION:")
print(f"🔗 Project : {project_url}")
print(f"📝 Log Stream: {log_stream_url}")
```
Loading