במאמר הזה מוסבר איך לשנות הגדרת רישום ביומן של OpenTelemetry Collector שמשתמשת ב-exporter קיים – במקרה הזה, googlecloud logging exporter – כדי להשתמש ב-OTLP exporter וב-Telemetry (OTLP) API, telemetry.googleapis.com.
הפעלת Telemetry API
ה-exporter של OTLP כותב ל-Telemetry API, ולכן צריך להפעיל את ה-API הזה בפרויקט. מפעילים את Telemetry API באמצעות הפקודה הבאה:
gcloud services enable telemetry.googleapis.com
איתור כלי הייצוא שרוצים להחליף
בקובץ ההגדרות, מאתרים את הרשומה exporters לרישום ביומן. ההגדרה שלכם יכולה להיראות כך:
exporters:
googlecloud/logging:
מחליפים את googlecloud/logging exporter ומוסיפים את התוסף googleauthclient:
exporters:
otlp_grpc/otlp_logs:
auth:
authenticator: googleclientauth
balancer_name: pick_first
endpoint: telemetry.googleapis.com:443
extensions:
googleclientauth: {}
הוספת מעבדים
בקובץ ההגדרות, מאתרים את הרשומה processors. ההגדרה שלכם עשויה להיראות כך:
processors:
resourcedetection/_global_0: [...details omitted...]
transform/mylog__source_0: [...details omitted...]
מעתיקים את ההגדרות של כל אחד מהמעבדים הבאים ומדביקים אותן בקובץ ההגדרות:
מעבד
resourceשאוסף מידע על הפרויקט שלכם ב- Google Cloud .resource/gcp_project_id: attributes: - action: insert value: PROJECT_ID key: gcp.project_idtransformמעבד ששומר על מידע לגבי מקור המדידה ומאפייני שירות המשאבים.transform/otlp_grpc/preserve_instrumentation_source_version: error_mode: ignore log_statements: - context: log statements: - set(attributes["instrumentation_source"], instrumentation_scope.name) where instrumentation_scope.name != "" - set(attributes["instrumentation_version"], instrumentation_scope.version) where instrumentation_scope.version != "" - set(attributes["service.name"], resource.attributes["service.name"]) where resource.attributes["service.name"] != nil - set(attributes["service.namespace"], resource.attributes["service.namespace"]) where resource.attributes["service.namespace"] != nil - set(attributes["service.instance.id"], resource.attributes["service.instance.id"]) where resource.attributes["service.instance.id"] != nil
ההגדרה ששונתה נראית כך:
processors:
resourcedetection/_global_0: [...details omitted...]
transform/mylog__source_0: [...details omitted...]
resource/gcp_project_id: [...details omitted...]
transform/otlp_grpc/preserve_instrumentation_source_version: [...details omitted...]
שינוי שירות הרישום ביומן וצינור עיבוד הנתונים
בהגדרה, מאתרים את service שמשמש לרישום ביומן, שכולל pipeline שמשתמש ב-googlecloud/logging exporter. ההגדרה שלכם עשויה להיראות כך:
service:
pipelines:
logs/logs_my__pipeline_mylog__source:
exporters:
- googlecloud/logging
processors:
- transform/mylog__source_0
- resourcedetection/_global_0
receivers:
- tcplog
מבצעים את השינויים הבאים בהגדרה:
- מוסיפים את התוסף
googleclientauthלרשומהservice. - משנים את כלי הייצוא של צינור הנתונים ל-
otlp_grpc/otlp_logs. - מוסיפים את המעבדים החדשים לרשימת המעבדים של צינור העיבוד:
resource/gcp_project_idtransform/otlp_grpc/preserve_instrumentation_source_version
ההגדרה ששונתה נראית כך:
service:
extensions:
- googleclientauth
pipelines:
logs/logs_my__pipeline_mylog__source:
exporters:
- otlp_grpc/otlp_logs
processors:
- transform/mylog__source_0
- resourcedetection/_global_0
- resource/gcp_project_id
- transform/otlp_grpc/preserve_instrumentation_source_version
receivers:
- tcplog
העברת לוחות בקרה וכללי מדיניות התראות, אם יש צורך
אם יש לכם תרשימים או מדיניות התראות שעוקבים אחרי השימוש ב-Cloud Logging API, אתם צריכים לעדכן אותם כדי לעקוב אחרי השימוש ב-Telemetry API במקום זאת. הכלי OTLP exporter שולח יומנים לפרויקט שלכם ב- Google Cloud באמצעות Telemetry API במקום Cloud Logging API.