matrei commented on code in PR #15750: URL: https://github.com/apache/grails-core/pull/15750#discussion_r3462035657
########## grails-observation/src/main/java/org/grails/observation/GrailsObservationConvention.java: ########## @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.grails.observation; + +import io.micrometer.common.KeyValue; +import io.micrometer.common.docs.KeyName; +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationConvention; + +/** + * Base {@link ObservationConvention} for the Grails request-lifecycle observations. It provides the + * pieces every Grails convention shares — {@link #supportsContext} (by context type), the + * low-cardinality {@code error} key value, and the {@code null}/empty fallback helper — so concrete + * conventions only declare their own name, contextual name and observation-specific tags. + * + * @param <C> the {@link Observation.Context} type this convention handles + * @author Apache Grails + * @since 8.0.0 Review Comment: - Remove `@author`? - `@since 8.0`? ########## grails-observation/src/main/java/org/grails/observation/GrailsObservationKeyNames.java: ########## @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.grails.observation; + +import io.micrometer.common.docs.KeyName; + +/** + * {@link KeyName}s shared by every Grails request-lifecycle observation, so the common tags are + * defined once rather than redeclared per observation. + * + * @author Apache Grails + * @since 8.0.0 Review Comment: - Remove `@author` - `@since 8.0`? ########## grails-converters/src/main/groovy/grails/converters/JSON.java: ########## @@ -148,6 +155,29 @@ public void render(Writer out) throws ConverterException { * @throws ConverterException */ public void render(HttpServletResponse response) throws ConverterException { + ObservationRegistry registry = ConvertersConfigurationHolder.getObservationRegistry(); + if (registry == null || registry.isNoop()) { + renderInternal(response); + return; + } + Observation observation = ConverterObservationDocumentation.CONVERT.observation( + (ConverterObservationConvention) null, DEFAULT_CONVERT_CONVENTION, Review Comment: Do we need the cast? ########## grails-converters/src/main/groovy/grails/converters/JSON.java: ########## @@ -148,6 +155,29 @@ public void render(Writer out) throws ConverterException { * @throws ConverterException */ public void render(HttpServletResponse response) throws ConverterException { + ObservationRegistry registry = ConvertersConfigurationHolder.getObservationRegistry(); Review Comment: `var observationRegistry = `? ########## grails-converters/src/main/groovy/org/grails/web/converters/observation/ConverterObservationContext.java: ########## @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.web.converters.observation; + +import io.micrometer.observation.Observation; + +/** + * Observation context for the {@link ConverterObservationDocumentation#CONVERT} observation. + * + * @author Apache Grails + * @since 8.0.0 + */ Review Comment: - Remove `@author`? - `@since 8.0`? ########## grails-converters/src/main/groovy/org/grails/web/converters/observation/DefaultConverterObservationConvention.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.web.converters.observation; + +import io.micrometer.common.KeyValues; +import io.micrometer.common.docs.KeyName; + +import org.grails.observation.GrailsObservationConvention; +import org.grails.observation.GrailsObservationKeyNames; + +import static org.grails.web.converters.observation.ConverterObservationDocumentation.ConverterLowCardinalityKeyNames; + +/** + * Default {@link ConverterObservationConvention}. + * + * @author Apache Grails + * @since 8.0.0 + */ Review Comment: - Remove `@author`? - `@since 8.0`? - Will not comment on this further ########## grails-converters/src/main/groovy/org/grails/web/converters/observation/ConverterObservationDocumentation.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.web.converters.observation; + +import io.micrometer.common.docs.KeyName; +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationConvention; +import io.micrometer.observation.docs.ObservationDocumentation; + +import org.grails.observation.GrailsObservationKeyNames; + +/** + * {@link ObservationDocumentation} for serializing a value to the HTTP response via a Grails + * converter ({@code render obj as JSON} / {@code as XML}). + * + * @author Apache Grails + * @since 8.0.0 + */ Review Comment: - Remove `@author`? - `@since 8.0`? ########## grails-converters/src/main/groovy/grails/converters/JSON.java: ########## @@ -148,6 +155,29 @@ public void render(Writer out) throws ConverterException { * @throws ConverterException */ public void render(HttpServletResponse response) throws ConverterException { + ObservationRegistry registry = ConvertersConfigurationHolder.getObservationRegistry(); + if (registry == null || registry.isNoop()) { + renderInternal(response); + return; + } + Observation observation = ConverterObservationDocumentation.CONVERT.observation( + (ConverterObservationConvention) null, DEFAULT_CONVERT_CONVENTION, + () -> new ConverterObservationContext("json"), registry).start(); + Observation.Scope scope = observation.openScope(); Review Comment: `var observationScope = `? ########## grails-converters/src/main/groovy/grails/converters/JSON.java: ########## @@ -148,6 +155,29 @@ public void render(Writer out) throws ConverterException { * @throws ConverterException */ public void render(HttpServletResponse response) throws ConverterException { + ObservationRegistry registry = ConvertersConfigurationHolder.getObservationRegistry(); + if (registry == null || registry.isNoop()) { + renderInternal(response); + return; + } + Observation observation = ConverterObservationDocumentation.CONVERT.observation( Review Comment: `var observeration = `? ########## grails-converters/src/main/groovy/grails/converters/XML.java: ########## @@ -263,6 +270,29 @@ protected void handleCircularRelationship(Object o) throws ConverterException { } public void render(HttpServletResponse response) throws ConverterException { + ObservationRegistry registry = ConvertersConfigurationHolder.getObservationRegistry(); + if (registry == null || registry.isNoop()) { + renderInternal(response); + return; + } + Observation observation = ConverterObservationDocumentation.CONVERT.observation( + (ConverterObservationConvention) null, DEFAULT_CONVERT_CONVENTION, + () -> new ConverterObservationContext("xml"), registry).start(); + Observation.Scope scope = observation.openScope(); + try { + renderInternal(response); + } + catch (Throwable t) { + observation.error(t); + throw t; + } + finally { + scope.close(); + observation.stop(); + } + } + Review Comment: - Same comments as in `JSON.java` - Will not comment on this further ########## grails-converters/src/main/groovy/org/grails/web/converters/observation/ConverterObservationConvention.java: ########## @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.web.converters.observation; + +import io.micrometer.observation.ObservationConvention; + +/** + * {@link ObservationConvention} for the {@link ConverterObservationDocumentation#CONVERT} observation. + * The default implementation is {@link DefaultConverterObservationConvention}. + * + * @author Apache Grails + * @since 8.0.0 + */ Review Comment: - Remove `@author`? - `@since 8.0`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
