matt_elgazar
12/06/2023, 2:12 AMmeltano el tap-mongodb target-jsonl
logging.yaml
version: 1
disable_existing_loggers: false
formatters:
json:
(): meltano.core.logging.json_formatter
root:
level: INFO
propagate: yes
handlers: [console]
handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: json
stream: "<ext://sys.stderr>"
I’m a bit confused how meltano is generating logs. Is it with python logging library? In python I can see logs using google-cloud-logging
library:
import google.cloud.logging
client = google.cloud.logging.Client()
client.setup_logging()
<http://logging.info|logging.info>("*** INFO ***")
edgar_ramirez_mondragon
12/06/2023, 4:18 AMgoogle-cloud-logging
in the same virtualenv as Meltano (they should be compatible)
2. Write a custom python module that contains your logging handler callable
3. Set PYTHONPATH
to the directory containing the logging module
4. Check that Meltano is sending logs to cloud logging?
https://gist.github.com/edgarrmondragon/feb148d50339dbbc2a6251707e13882fmatt_elgazar
12/06/2023, 5:17 AMmeltano lock --all --update
Need help fixing this problem? Visit <http://melta.no/> for troubleshooting steps, or to
join our friendly Slack community.
Unable to configure handler 'google'
edgar_ramirez_mondragon
12/06/2023, 2:53 PMimport sys
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler
def get_handler():
"""Return a handler based on the environment."""
try:
client = google.cloud.logging.Client()
except Exception as e:
print(f"Failed to create logging client: {e}", file=sys.stderr)
raise
return CloudLoggingHandler(client)
matt_elgazar
12/06/2023, 4:33 PMUnable to configure handler 'google'
. If I run the python script python gcp_logging.py
it runs successfullymatt_elgazar
12/06/2023, 4:33 PMmeltano test
returns the google handler error. Are you not having this issue? I re-cloned a fresh meltano repo and ran the steps one by one on two different machines getting the same erroredgar_ramirez_mondragon
12/06/2023, 6:55 PMgoogle.cloud.logging.Client()
, so you could try moving the handler creating to the try block:
def get_handler():
"""Return a handler based on the environment."""
try:
client = google.cloud.logging.Client()
return CloudLoggingHandler(client)
except Exception as e:
print(f"Failed to create logging client: {e}", file=sys.stderr)
raise
With that I still get
PYTHONPATH=$PWD meltano test
Failed to create logging client: Your default credentials were not found. To set up Application Default Credentials, see <https://cloud.google.com/docs/authentication/external/set-up-adc> for more information.
Need help fixing this problem? Visit <http://melta.no/> for troubleshooting steps, or to
join our friendly Slack community.
Unable to configure handler 'google'
because I haven't configured cloud loggingmatt_elgazar
12/06/2023, 6:57 PMUnable to configure handler 'google'
. My gut is telling me it’s something that needs to be configured in logging.yamledgar_ramirez_mondragon
12/06/2023, 6:58 PMPYTHONPATH
set?edgar_ramirez_mondragon
12/06/2023, 6:58 PMmatt_elgazar
12/06/2023, 6:58 PMecho $PYTHONPATH
/home/melgazar9/meltano_projects/tap-yfinance
matt_elgazar
12/06/2023, 6:59 PMedgar_ramirez_mondragon
12/06/2023, 6:59 PMdef get_handler():
"""Return a handler based on the environment."""
try:
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler
client = google.cloud.logging.Client(project="<your project id>")
except Exception as e:
print(f"Failed to create logging client: {e}", file=sys.stderr)
raise
return CloudLoggingHandler(client)
matt_elgazar
12/06/2023, 7:01 PMmatt_elgazar
12/06/2023, 7:01 PMlogging.yaml
”
Google Cloud logging config
version: 1
disable_existing_loggers: false
formatters:
json:
(): meltano.core.logging.json_formatter
handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: json
stream: "<ext://sys.stderr>"
root:
level: INFO
propagate: yes
handlers: [console]
matt_elgazar
12/06/2023, 7:02 PMgoogle.cloud.logging.handlers.CloudLoggingHandler
?matt_elgazar
12/06/2023, 7:05 PMhandlers:
console:
class: google.cloud.logging.handlers.CloudLoggingHandler
level: INFO
formatter: json
stream: "<ext://sys.stderr>"
I get this error now:
Unable to configure handler 'console'
edgar_ramirez_mondragon
12/06/2023, 7:05 PMCloudRun
captures stderr automatically so yeah that basic config should work there but if you want to explicitly use "Cloud Logging for Python", then you do need something like the gist.
I got it working btw:
• gcp_logging.py
import sys
def get_handler():
"""Return a handler based on the environment."""
try:
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler
client = google.cloud.logging.Client(project="personal-warehouse-349804")
except Exception as e:
print(f"Failed to create logging client: {e}", file=sys.stderr)
raise
return CloudLoggingHandler(client)
• google.yaml
version: 1
disable_existing_loggers: false
handlers:
google:
(): gcp_logging.get_handler
root:
level: INFO
handlers: [google]
edgar_ramirez_mondragon
12/06/2023, 7:06 PMedgar_ramirez_mondragon
12/06/2023, 7:07 PMmatt_elgazar
12/06/2023, 7:07 PMlogging/google.yaml
you created a logging directory and put google.yaml in there?matt_elgazar
12/06/2023, 7:08 PMedgar_ramirez_mondragon
12/06/2023, 7:08 PMmeltano config meltano set cli.log_config
matt_elgazar
12/06/2023, 7:10 PMmeltano_projects/tap-yfinance
--- did you set your PYTHONPATH=meltano_projects/tap-yfinance
?edgar_ramirez_mondragon
12/06/2023, 7:13 PM.
├── gcp_logging.py
├── logging
│ └── google.yaml
└── meltano.yml
And I run PYTHONPATH=$PWD meltano ...
from the root of the project. gcp_logging.py
should be in meltano_projects/tap-yfinance
in your casematt_elgazar
12/06/2023, 7:16 PMUnable to configure handler 'google'
matt_elgazar
12/06/2023, 7:17 PMmatt_elgazar
12/06/2023, 7:21 PMcd tap-yfinance
--- Create gcp_logging.py
and google.yaml
copying your above code snippets
3. pipx ensurepath
4. pipx inject meltano google-cloud-logging
5. meltano config meltano set cli.log_config google.yaml
6. export PYTHONPATH=$PWD meltano test
7. meltano lock --all --update
Unable to configure handler 'google'
• Repeat the above but try putting google.yaml
in the logging/
directory.
• Try the same steps as above on both MacOS and Ubuntu linux.matt_elgazar
12/06/2023, 7:27 PMedgar_ramirez_mondragon
12/06/2023, 8:16 PMecho $PYTHONPATH
?matt_elgazar
12/06/2023, 8:20 PM/Users/melgazar9/meltano_projects/tap-yfinance
edgar_ramirez_mondragon
12/06/2023, 9:39 PMimport sys
def get_handler():
"""Return a handler based on the environment."""
try:
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler
client = google.cloud.logging.Client(project="<your-project-name>")
return CloudLoggingHandler(client)
except Exception as e:
print(f"Failed to create logging client: {e}", file=sys.stderr)
raise
matt_elgazar
12/06/2023, 9:43 PMUnable to configure handler 'google'
.
I started a branch new VM on gcp (and also locally on MacOS), installed git, meltano, pip, pipx, and followed these steps directly getting the same error above: https://meltano.slack.com/archives/C01TCRBBJD7/p1701890466285389?thread_ts=1701828771.518699&cid=C01TCRBBJD7matt_elgazar
12/06/2023, 10:35 PMedgar_ramirez_mondragon
12/06/2023, 11:52 PMmatt_elgazar
12/07/2023, 12:31 AMUnable to configure handler 'google'
from this line:
cli:
log_config: google.yaml
edgar_ramirez_mondragon
12/07/2023, 6:35 PMmatt_elgazar
12/07/2023, 6:37 PMmatt_elgazar
12/07/2023, 7:36 PMsent all pending logs
but I don't see any logs in GCP cloud logging. Are you able to see the actual logs in gcp cloud logging?edgar_ramirez_mondragon
12/07/2023, 8:01 PMFor an application to write logs by using the Cloud Logging library for Python, the service account for the underlying resource must have the Logs Writer (roles/logging.logWriter) IAM role. Most Google Cloud environments automatically configure the default service account to have this role.
https://cloud.google.com/logging/docs/setup/python#run-gce
matt_elgazar
12/07/2023, 9:30 PMmatt_elgazar
12/07/2023, 10:29 PMsetup_logging()
using meltano? Maybe it's something under the hood in singer?
import google.cloud.logging
client = google.cloud.logging.Client()
client.setup_logging()
<http://logging.info|logging.info>("*** INFO ***")
edgar_ramirez_mondragon
12/07/2023, 11:08 PMsetup_logging()
is necessary if you're using python's logging library. I just followed the instructions in the link
Use the Compute Engine default service account or another service account of your choice, and select Allow full access to all Cloud APIs in the Identity and API access section.I also changed the level in
google.yaml
to DEBUG to get more logs:
version: 1
disable_existing_loggers: false
handlers:
google:
(): gcp_logging.get_handler
project: "personal-warehouse-349804"
logger_name: meltano
root:
level: DEBUG
handlers: [google]
And it worked!edgar_ramirez_mondragon
12/07/2023, 11:10 PMsetup_logging()
to the handler module
import sys
def get_handler(*, project=None, logger_name=None):
"""Return a handler based on the environment."""
try:
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler
client = google.cloud.logging.Client(project=project)
client.setup_logging() # <- HERE
return CloudLoggingHandler(client, name=logger_name)
except Exception as e:
print(f"Failed to create logging client: {e}", file=sys.stderr)
raise
I just got duplicate init messages:
Waiting up to 5 seconds.
Sent all pending logs.
Waiting up to 5 seconds.
Sent all pending logs.
So I think CloudLoggingHandler
calls setup_logging()
under the hood.matt_elgazar
12/08/2023, 12:04 AM