Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterjam authored Apr 9, 2024
2 parents ca8fbe6 + 9247f62 commit 518528d
Show file tree
Hide file tree
Showing 23 changed files with 958 additions and 768 deletions.
6 changes: 2 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
"zeshuaro.vscode-python-poetry"
],
"settings": {
"azureFunctions.projectSubpath": "code/backend/batch",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.pythonPath": "/usr/local/bin/python",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
"remote.autoForwardPortsFallback": 0,
"remote.autoForwardPortsSource": "process"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/comment_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
script: |
const response = await github.rest.pulls.list({
owner: "${{ github.repository_owner }}",
repo: "${{ github.event.workflow_run.repository.name }}",
repo: context.payload.workflow_run.repository.name,
state: "open",
head: "${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }}",
head: `${context.payload.workflow_run.head_repository.owner.login}:${context.payload.workflow_run.head_branch}`,
});
return response.data[0]?.number ?? "";
Expand Down
9 changes: 8 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@
"envFile": "${input:dotEnvFilePath}",
}
],
"compounds": [
{
"name": "Launch Frontend",
"configurations": [ "Launch Frontend (UI)", "Launch Frontend (api)" ],
"stopAll": true
}
],
"inputs": [
{
"id": "dotEnvFilePath",
"type": "command",
"command": "azure-dev.commands.getDotEnvFilePath"
}
]
}
}
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"azureFunctions.deploySubpath": "code\\backend\\batch",
"azureFunctions.deploySubpath": "code/backend/batch",
"azureFunctions.projectSubpath": "code/backend/batch",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 2,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"githubPullRequests.ignoredPullRequestBranches": [
"main"
],
Expand Down
72 changes: 44 additions & 28 deletions README.md

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion code/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor

configure_azure_monitor()
# We cannot use EnvHelper here as Application Insights should be configured first
# for instrumentation to work correctly
if os.getenv("APPINSIGHTS_ENABLED", "false").lower() == "true":
configure_azure_monitor()
HTTPXClientInstrumentor().instrument() # httpx is used by openai

from create_app import create_app # noqa: E402

Expand Down
5 changes: 4 additions & 1 deletion code/backend/Admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

configure_azure_monitor()
# We cannot use EnvHelper here as Application Insights needs to be configured first
# for instrumentation to work correctly
if os.getenv("APPINSIGHTS_ENABLED", "false").lower() == "true":
configure_azure_monitor()

logger = logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
logging.WARNING
Expand Down
3 changes: 2 additions & 1 deletion code/backend/batch/utilities/common/SourceDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def from_metadata(
hash_key = f"doc_{hash_key}"
sas_placeholder = (
"_SAS_TOKEN_PLACEHOLDER_"
if "blob.core.windows.net" in parsed_url.netloc
if parsed_url.netloc
and parsed_url.netloc.endswith(".blob.core.windows.net")
else ""
)
return cls(
Expand Down
3 changes: 2 additions & 1 deletion code/backend/batch/utilities/helpers/EnvHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def __init__(self, **kwargs) -> None:
"AZURE_FORM_RECOGNIZER_KEY"
)
# Azure App Insights
self.APPINSIGHTS_ENABLED = self.get_env_var_bool("APPINSIGHTS_ENABLED")
# APPINSIGHTS_ENABLED will be True when the application runs in App Service
self.APPINSIGHTS_ENABLED = self.get_env_var_bool("APPINSIGHTS_ENABLED", "False")

self.APPINSIGHTS_CONNECTION_STRING = os.getenv(
"APPINSIGHTS_CONNECTION_STRING", ""
Expand Down
13 changes: 2 additions & 11 deletions code/backend/batch/utilities/loggers/TokenLogger.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import logging
from opencensus.ext.azure.log_exporter import AzureLogHandler
from ..helpers.EnvHelper import EnvHelper


# TODO: We probably don't need a separate class for this
class TokenLogger:
def __init__(self, name: str = __name__):
env_helper: EnvHelper = EnvHelper()
self.logger = logging.getLogger(name)
if env_helper.APPINSIGHTS_ENABLED:
self.logger.addHandler(
AzureLogHandler(
connection_string=env_helper.APPINSIGHTS_CONNECTION_STRING
)
)
self.logger.setLevel(logging.INFO)

def get_logger(self):
return self.logger

def log(self, message: str, custom_dimensions: dict):
# Setting log properties
log_properties = {"custom_dimensions": custom_dimensions}
self.logger.info(message, extra=log_properties)
self.logger.info(message, extra=custom_dimensions)
Loading

0 comments on commit 518528d

Please sign in to comment.